Skip to content

Commit 13875d0

Browse files
arturovtthePunderWoman
authored andcommitted
refactor(common): remove redundant ɵloadImpl check in client bundles (angular#62191)
In this commit, the conditional branching around `ɵloadImpl` is removed from client-side code, as `ɵloadImpl` is never defined in client bundles. This makes the logic simpler and improves tree-shaking, allowing the `from()` import to be dropped from the common bundle in browser builds. PR Close angular#62191
1 parent 4def2a7 commit 13875d0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • packages/common/http/src

packages/common/http/src/xhr.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ export class HttpXhrBackend implements HttpBackend {
114114
// for various non-browser environments. We currently limit it to only `ServerXhr`
115115
// class, which needs to load an XHR implementation.
116116
const xhrFactory: XhrFactory & {ɵloadImpl?: () => Promise<void>} = this.xhrFactory;
117-
const source: Observable<void | null> = xhrFactory.ɵloadImpl
118-
? from(xhrFactory.ɵloadImpl())
119-
: of(null);
117+
const source: Observable<void | null> =
118+
// Note that `ɵloadImpl` is never defined in client bundles and can be
119+
// safely dropped whenever we're running in the browser.
120+
// This branching is redundant.
121+
// The `ngServerMode` guard also enables tree-shaking of the `from()`
122+
// function from the common bundle, as it's only used in server code.
123+
typeof ngServerMode !== 'undefined' && ngServerMode && xhrFactory.ɵloadImpl
124+
? from(xhrFactory.ɵloadImpl())
125+
: of(null);
120126

121127
return source.pipe(
122128
switchMap(() => {

0 commit comments

Comments
 (0)