Skip to content

fix(@angular/build): include source map hashes in optimized chunk hashes - #34583

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix/chunk-optimizer-sourcemap-hash
Open

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix/chunk-optimizer-sourcemap-hash

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

When sourceMap.scripts is enabled, injectDebugIds appends a //# debugId=<uuid> comment derived from the chunk's source map content to each emitted browser JS file after chunk optimization.

While esbuild includes source map content when computing output chunk hashes, optimizeChunks strips the esbuild hash and relies on Rolldown to compute [hash] for optimized chunks. Because Rolldown only hashed the JS code and not the input source maps, a source change that only altered the source map (such as adding or removing type definitions or comments that shifted line numbers) changed the debugId bytes in the emitted JS file and its SRI hash in index.html without changing the chunk's filename.

Implement augmentChunkHash in the chunk optimizer's angular-bundle plugin to include the input source map hashes when source maps are enabled, and invalidate cached BuildOutputFile hashes when contents are mutated.

Closes #34574

When `sourceMap.scripts` is enabled, `injectDebugIds` appends a
`//# debugId=<uuid>` comment derived from the chunk's source map content
to each emitted browser JS file after chunk optimization.

While esbuild includes source map content when computing output chunk
hashes, `optimizeChunks` strips the esbuild hash and relies on Rolldown
to compute `[hash]` for optimized chunks. Because Rolldown only hashed
the JS code and not the input source maps, a source change that only
altered the source map (such as adding or removing type definitions or
comments that shifted line numbers) changed the `debugId` bytes in the
emitted JS file and its SRI hash in `index.html` without changing the
chunk's filename.

Implement `augmentChunkHash` in the chunk optimizer's `angular-bundle`
plugin to include the input source map hashes when source maps are
enabled, and invalidate cached `BuildOutputFile` hashes when `contents`
are mutated.

Closes angular#34574

@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 ensures that optimized chunk filenames are updated when source map changes occur, even if the emitted JS code remains unchanged. This is achieved by augmenting the chunk hash with module source map hashes in the chunk optimizer and updating convertOutputFile to dynamically calculate and cache file hashes when contents change. A test case has been added to verify this behavior. The review feedback suggests improving type safety in bundler-files.ts by using a type assertion and nullish coalescing when initializing cachedHash to prevent potential TypeScript compilation errors under strict null checks.

Comment thread packages/angular/build/src/tools/esbuild/bundler-files.ts
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Oct 29, 2026
@alan-agius4
alan-agius4 requested a review from clydin October 29, 2026 08:32
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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug ID changes the bytes of an optimized chunk but not its file name, so cached files fail the SRI check

1 participant