-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/build): stabilize chunk hashes during i18n inlining #32889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maruthang
wants to merge
1
commit into
angular:main
Choose a base branch
from
maruthang:fix-30675-i18n-cache-busting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−35
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/angular/build/src/builders/application/tests/options/i18n-output-hashing_spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { buildApplication } from '../../index'; | ||
| import { OutputHashing } from '../../schema'; | ||
| import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
|
||
| describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
| describe('i18n output hashing', () => { | ||
| beforeEach(() => { | ||
| harness.useProject('test', { | ||
| root: '.', | ||
| sourceRoot: 'src', | ||
| cli: { | ||
| cache: { | ||
| enabled: false, | ||
| }, | ||
| }, | ||
| i18n: { | ||
| locales: { | ||
| 'fr': 'src/locales/messages.fr.xlf', | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should not include a global i18n hash footer in localized output files', async () => { | ||
| harness.useTarget('build', { | ||
| ...BASE_OPTIONS, | ||
| localize: true, | ||
| outputHashing: OutputHashing.None, | ||
| }); | ||
|
|
||
| await harness.writeFile( | ||
| 'src/app/app.component.html', | ||
| ` | ||
| <p id="hello" i18n="An introduction header for this sample">Hello {{ title }}! </p> | ||
| `, | ||
| ); | ||
|
|
||
| await harness.writeFile('src/locales/messages.fr.xlf', TRANSLATION_FILE_CONTENT); | ||
|
|
||
| const { result } = await harness.executeOnce(); | ||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| // Verify that the main JS output file does not contain a global i18n footer hash comment. | ||
| // Previously, all JS files included a `/**i18n:<sha256>*/` footer computed from ALL | ||
| // translation files, causing all chunk hashes to change whenever any translation | ||
| // changed (issue #30675). | ||
| harness | ||
| .expectFile('dist/browser/fr/main.js') | ||
| .content.not.toMatch(/\/\*\*i18n:[0-9a-f]{64}\*\//); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| const TRANSLATION_FILE_CONTENT = ` | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> | ||
| <file target-language="fr" datatype="plaintext" original="ng2.template"> | ||
| <body> | ||
| <trans-unit id="4286451273117902052" datatype="html"> | ||
| <target>Bonjour <x id="INTERPOLATION" equiv-text="{{ title }}"/>! </target> | ||
| <context-group purpose="location"> | ||
| <context context-type="targetfile">src/app/app.component.html</context> | ||
| <context context-type="linenumber">2,3</context> | ||
| </context-group> | ||
| <note priority="1" from="description">An introduction header for this sample</note> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> | ||
| `; |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for generating the 8-character uppercase alphanumeric hash (
hashValue.toString(36).slice(0, 8).toUpperCase().padStart(8, '0')) is quite dense. Extracting this into a small, private helper method (e.g.,_generateShortHash) would improve readability and encapsulate this specific hashing algorithm.