Skip to content

fix(@angular/build): consolidate initial shared chunks into main with Rolldown - #34408

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix/rolldown-initial-chunk-consolidation
Oct 20, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix/rolldown-initial-chunk-consolidation

Conversation

@clydin

@clydin clydin commented Oct 19, 2026

Copy link
Copy Markdown
Member

When esbuild bundles an application with lazy-loaded routes, modules that are statically reachable from the main entry point and also imported by different subsets of lazy routes are split into separate shared chunks, often forming multi-level import chains from main.js. Previously, the Rollup-based chunk optimization pass recognized that the main entry point is always loaded before any dynamic import can execute and merged all modules in its static closure back into main.js.

After switching chunk optimization to Rolldown, unconfigured Rolldown only merged direct single-hop shared chunks into main.js while leaving deeper initial shared chunks as separate files. Configuring Rolldown with preserveEntrySignatures set to allow-extension and a codeSplitting group targeting the built-in $initial tag restores the consolidation of all initial shared modules into the main entry chunk while keeping lazy-only shared chunks separate.

… Rolldown

When esbuild bundles an application with lazy-loaded routes, modules that are statically
reachable from the main entry point and also imported by different subsets of lazy routes are
split into separate shared chunks, often forming multi-level import chains from main.js.
Previously, the Rollup-based chunk optimization pass recognized that the main entry point is
always loaded before any dynamic import can execute and merged all modules in its static
closure back into main.js.

After switching chunk optimization to Rolldown, unconfigured Rolldown only merged direct
single-hop shared chunks into main.js while leaving deeper initial shared chunks as separate
files. Configuring Rolldown with preserveEntrySignatures set to allow-extension and a
codeSplitting group targeting the built-in $initial tag restores the consolidation of all
initial shared modules into the main entry chunk while keeping lazy-only shared chunks
separate.
@clydin
clydin force-pushed the fix/rolldown-initial-chunk-consolidation branch from d6d8b8f to 9aec53b Compare October 20, 2026 13:16
@clydin
clydin marked this pull request as ready for review October 20, 2026 13:18
@clydin clydin added the target: minor This PR is targeted for the next minor release label Oct 20, 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 optimizes chunking in the Angular application builder when using Rolldown by consolidating initial shared modules into the main chunk and adding a fallback mechanism to handle top-level await (TLA) scenarios. Corresponding integration tests have also been added. Regarding the review feedback, there is a potential runtime TypeError when checking for empty entry facades, as chunk.modules can be undefined and should be accessed safely using optional chaining or a nullish coalescing operator.

Comment thread packages/angular/build/src/builders/application/chunk-optimizer.ts
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 20, 2026
@clydin
clydin requested a review from alan-agius4 October 20, 2026 13:50

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 20, 2026
@alan-agius4
alan-agius4 merged commit 97efdcf into angular:main Oct 20, 2026
43 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@clydin
clydin deleted the fix/rolldown-initial-chunk-consolidation branch October 20, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants