Skip to content

fix(@angular/build): preserve unaffected localized chunk URLs - #34673

Closed
splincode wants to merge 1 commit into
angular:mainfrom
splincode:fix/i18n-stable-browser-chunk-hashes
Closed

splincode wants to merge 1 commit into
angular:mainfrom
splincode:fix/i18n-stable-browser-chunk-hashes

Conversation

@splincode

Copy link
Copy Markdown

PR Checklist

  • The commit message follows the guidelines
  • Regression tests were added to the existing i18n suites
  • Docs were updated (no public option changes)

PR Type

  • Bugfix

What is the current behavior?

The application builder adds a digest of the translation files to every JavaScript bundle. Editing one locale can give unrelated chunks new URLs in every locale, forcing browsers to download them again.

Fixes #30675.

What is the new behavior?

For one-shot browser builds with bundle hashing enabled, compute names after localization. A changed bundle gets a new URL, and bundles that reference it get updated URLs. Unchanged bundles retain their URLs. The dependency graph comes from the esbuild/Rolldown output metadata; JavaScript is parsed when references need to be rewritten or to find worker URLs that are absent from the graph.

Watch, server builds, and builds with custom code plugins keep the existing hashing path.

Does this PR introduce a breaking change?

  • Yes
  • No

Measurements and verification

Chromium 153, warm browser cache. Changed one French XLF message used by a lazy chunk, switched deployments on the same origin, and opened the page and one independent lazy chunk. JS used immutable cache headers; HTML used no-store. All three runs per locale and variant gave the same results. Bytes are Brotli response bodies, excluding headers.

Locale JS responses (main → PR) JS bytes downloaded (main → PR)
French, translation changed 5 → 2 36,822 → 34,974 (−5.0%)
German, translation unchanged 5 → 0 36,596 → 0

Build time. Synthetic Angular app with 240 lazy routes, three locales and 254 JS outputs per locale. Five alternating pairs per mode, after a warm-up pair; CLI disk cache disabled. The full build compares this PR with upstream main. The rehash stage compares the metadata approach with the initial implementation that parsed JavaScript to build the graph.

Source maps Full build, median paired delta vs. main (range) Rehash stage, initial implementation → metadata
Off +30 ms (−128 to +308 ms) 370 → 77 ms
On +138 ms (−106 to +298 ms) 404 → 124 ms

The stage timings are separate instrumented runs, including graph construction. These figures describe the test fixtures, not production CDN traffic or general build performance.

Validation. Ran 50 i18n tests and the localized-hashes e2e scenario locally, including sourcemap references and SHA-384 integrity for the emitted entry bundle. Checked localized workers in Chromium with esbuild and Rolldown. The initial --watch build and two rebuilds after editing a lazy TypeScript module produced identical filenames and SHA-256 digests for the entry bundle, lazy chunk and HTML on main and the PR branch. Each rebuild updated the import and removed the old chunk.

@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 localized content hashing for Angular builds, implementing a new utility createLocalizedOutputHasher to rename localized browser scripts based on content and dependency changes. Feedback on the changes includes a critical correction to the worker script regular expressions to support lowercase and mixed-case hashes, as well as a recommendation to resolve variable shadowing of path in the build execution file.

@splincode
splincode force-pushed the fix/i18n-stable-browser-chunk-hashes branch from 4d935bc to bb6e7f6 Compare November 8, 2026 11:22
@alan-agius4

Copy link
Copy Markdown
Collaborator

Thanks for working on this and looking into #30675!

After reviewing the approach, we don't want to introduce a post-bundler AST/regex pass that re-parses emitted bundles and rewrites chunk filenames per locale. The application builder pipeline assumes a single shared bundle graph across locales (for browser-stats.json, CLI build stats, bundle budget checks, injectDebugIds, and SSR/prerendering entryPointToBrowserMapping), so renaming chunks per locale after bundling creates inconsistencies across those features and leaves SSR/prerendered apps unsupported. It also adds significant complexity and main-thread parsing overhead after I18nInliner has already processed the bundles.

We're going to close this PR as this would need a different architectural approach within the bundler/inlining pipeline itself. Thanks again for your contribution!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i18n causes esbuild chunks to be cache-busted on each deploy

2 participants