Skip to content

perf(@angular/build): avoid duplicate Domino bundling in server bundles - #34527

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf-server-domino-dedup
Open

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:perf-server-domino-dedup

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

PR Checklist

[✓] The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines
[✓] Tests for the changes have been added (for bug fixes / features)
[ ] Docs have been added / updated (for bug fixes / features)

PR Type

[ ] Bugfix
[✓] Feature / Performance
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

When bundling an application with server-side rendering, Domino (~560 KB unminified) is bundled into both polyfills.server.mjs (via @angular/platform-server/init) and main.server.mjs (via @angular/platform-server).

What is the new behavior?

Domino is bundled only once in polyfills.server.mjs and attached to globalThis['ɵdomino']. The main server bundle redirects Domino imports to this shared instance.

This replaces the redundant bundled copy of Domino in main.server.mjs without requiring manual filesystem probing or additionalContent parameter threading in polyfill options.

Does this PR introduce a breaking change?

[ ] Yes
[✓] No

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Oct 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two new esbuild plugins to ensure Domino is bundled only once for the server. The first plugin exposes the Domino instance on globalThis within the server polyfills bundle, and the second redirects Domino imports in the main server bundle to consume this global instance. Behavior tests have also been added to verify this sharing. The review feedback highlights a potential runtime issue where exporting Domino as a default export in the consumer plugin could break namespace imports, and suggests using CommonJS module.exports to ensure compatibility.

@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Oct 26, 2026
@alan-agius4 alan-agius4 added freq4: critical Happens to many users every day action: review The PR is still awaiting reviews from at least one requested reviewer and removed freq4: critical Happens to many users every day labels Oct 26, 2026
@alan-agius4
alan-agius4 requested a review from clydin October 26, 2026 09:37
@angular angular deleted a comment from gemini-code-assist Bot Oct 26, 2026
Avoid bundling duplicate copies of Domino in both the server polyfills bundle and the main server bundle.

The server polyfills bundle exposes the Domino instance attached to globalThis['ɵdomino'] when @angular/platform-server/init is bundled, and the main server bundle redirects Domino imports to this shared instance.
@alan-agius4
alan-agius4 force-pushed the perf-server-domino-dedup branch from 7814f94 to 58f0583 Compare October 26, 2026 10:28
*
* @returns An esbuild plugin.
*/
export function createPlatformServerDominoPlugin(): Plugin {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe createPlatformServerDominoRedirectPlugin or similar for symmetry with the above plugin?

Comment on lines +35 to +38
? {
path: resolve(args.resolveDir, args.path),
namespace: 'angular:domino-expose',
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? {
path: resolve(args.resolveDir, args.path),
namespace: 'angular:domino-expose',
}
? {
path: 'angular:platform-server-domino',
namespace: 'angular:domino-expose',
pluginData: {
importPath: args.path,
resolveDir: args.resolveDir,
},
}

To avoid passing the absolute path into the build outputs. Relevant changes would be needed to consume that in the onLoad hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build area: performance Issues related to performance target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server build bundles two copies of Domino, so DOM globals from init and the DominoAdapter are different classes

2 participants