Repository navigation
perf(@angular/build): bundle a single copy of domino for the server - #34516
Open
ChristopherPHolder wants to merge 1 commit into
Open
ChristopherPHolder wants to merge 1 commit into
ChristopherPHolder wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to share a single bundled copy of Domino (from @angular/platform-server/init in the server polyfills bundle) across other server bundles, rather than bundling it multiple times. This is achieved by exporting Domino from the server polyfills bundle and redirecting imports in other server bundles to this exported copy using a new esbuild plugin (platform-server-domino-plugin). A comprehensive test suite has also been added to verify this behavior under various configurations. I have no further feedback to provide as there are no review comments.
`@angular/platform-server/init` (bundled into the server polyfills) and `@angular/platform-server` (bundled into the main server bundle) both import the domino DOM implementation shipped with the package. As the two bundles are separate esbuild contexts, each output contained its own copy, and both were evaluated at runtime. Besides the size and memory cost, the two copies are distinct class hierarchies: DOM globals captured at module evaluation time (the scenario `init` exists for) come from the polyfills copy, while the platform renders with the other, so `instanceof` checks between them fail. The server polyfills bundle now re-exports the domino module it already contains, and the main server bundle redirects the `@angular/platform-server` import of domino to that export. The polyfills bundle is already imported first and marked external by every server bundle, which keeps the evaluation order unchanged. Fixes angular#34514
ChristopherPHolder
force-pushed
the
build-single-domino-copy
branch
from
October 23, 2026 21:35
6a6708e to
9f1c146
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.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #34514
The server build emits two complete copies of domino:
polyfills.server.mjsbundles it via@angular/platform-server/init, andmain.server.mjsbundles it again via@angular/platform-server. The two bundles are separate esbuild contexts, so the sharedthird_party/domino/bundled-domino.mjsmodule is inlined into each, and both are evaluated at runtime (main.server.mjsimports./polyfills.server.mjsfirst).Because the two copies are distinct class hierarchies, DOM globals captured at module-evaluation time (the scenario
initexists for) do not match the classes the platform renders with:What is the new behavior?
The server polyfills bundle re-exports the domino module it already contains, and the main server bundle redirects the
@angular/platform-serverimport of../third_party/domino/bundled-domino.mjsto that export../polyfills.server.mjsis already inSERVER_GENERATED_EXTERNALSand imported first by every server bundle, so the evaluation order is unchanged.The polyfills bundle has to stay a separate, externally imported file: with code splitting, a side-effect import at the top of the
main.serverentry is inlined into the entry while shared chunks are hoisted above it, so moving theinitimport there would run it after shared application chunks. Sharing the copy avoids that.On the default
ng new --ssrapp (Angular CLI 22.2.4, Node 26.8.1):bundled-domino.mjsinmain.server.mjsmain.server.mjs(production)main.server.mjsbody instanceof capturedHTMLElementCovered:
outputMode: 'server', the legacyssr+prerenderpath (same esbuild context and banner),platform: 'neutral', prerendering, and the dev server when bundling. When packages are external (ng serveprebundling) nothing changes; Node's module cache already shares one copy there. If@angular/platform-serveris not installed, is external, or has an unexpected layout, both sides fall back to today's behavior.Reproduction with the measurement harness and the
instanceofprobe: https://github.com/ChristopherPHolder/ng-double-dominoDoes this PR introduce a breaking change?
Other information
@angular/platform-server/initis still added to every server build. Making that optional (and the server polyfills list user-controllable in general) is a separate request: #34515.