fix(platform-server): make xhr2 import tree-shakable for restricted bundlers#68626
Open
arturovt wants to merge 1 commit intoangular:mainfrom
Open
fix(platform-server): make xhr2 import tree-shakable for restricted bundlers#68626arturovt wants to merge 1 commit intoangular:mainfrom
arturovt wants to merge 1 commit intoangular:mainfrom
Conversation
…undlers
`ServerXhr` previously contained a hard-coded dynamic `import('xhr2')`
inside `ɵloadImpl()`, which caused bundlers in restricted environments
such as Cloudflare Workers or V8 isolates to fail when resolving the
Node.js-only `xhr2` package — even when the default `FetchBackend` was
in use and `ServerXhr` was never instantiated at runtime.
Introduces a `SERVER_XHR2_LOADER` injection token in `@angular/common/http`
that carries the `() => import('xhr2')` factory. `withXhr()` provides
the token only in server mode via an `ngServerMode` guard, so the dynamic
import is absent from SSR bundles using the default `FetchBackend` and is
eliminated from browser bundles entirely. `ServerXhr` injects the token
optionally, preserving full XHR behaviour for applications that explicitly
opt in with `withXhr()`.
1c5972e to
97fc939
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ServerXhrpreviously contained a hard-coded dynamicimport('xhr2')insideɵloadImpl(), which caused bundlers in restricted environments such as Cloudflare Workers or V8 isolates to fail when resolving the Node.js-onlyxhr2package — even when the defaultFetchBackendwas in use andServerXhrwas never instantiated at runtime.Introduces a
SERVER_XHR2_LOADERinjection token in@angular/common/httpthat carries the() => import('xhr2')factory.withXhr()provides the token only in server mode via anngServerModeguard, so the dynamic import is absent from SSR bundles using the defaultFetchBackendand is eliminated from browser bundles entirely.ServerXhrinjects the token optionally, preserving full XHR behaviour for applications that explicitly opt in withwithXhr().