Skip to content

fix(platform-server): make xhr2 import tree-shakable for restricted bundlers#68626

Open
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:fix/xhr2-with-wrangler
Open

fix(platform-server): make xhr2 import tree-shakable for restricted bundlers#68626
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:fix/xhr2-with-wrangler

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

@arturovt arturovt commented May 7, 2026

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().

…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()`.
@arturovt arturovt force-pushed the fix/xhr2-with-wrangler branch from 1c5972e to 97fc939 Compare May 7, 2026 21:22
@angular-robot angular-robot Bot added the area: server Issues related to server-side rendering label May 7, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 7, 2026
@JeanMeche JeanMeche marked this pull request as ready for review May 7, 2026 22:59
@pullapprove pullapprove Bot requested a review from JeanMeche May 7, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: server Issues related to server-side rendering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant