Skip to content

Conversation

@roma-claudio
Copy link
Contributor

@roma-claudio roma-claudio commented Nov 7, 2025

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

  • Bugfix
  • Feature
  • 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?

@angular/localize scripts are always removed when inline transformations are enabled, even though not all the scripts/dependencies might have been transformed

Issue Number: N/A

What is the new behavior?

@angular/localize scripts will only be removed when inline transformations are enabled and all the scripts/dependencies are actually transformed

Does this PR introduce a breaking change?

  • Yes
  • No

@google-cla
Copy link

google-cla bot commented Nov 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@roma-claudio roma-claudio changed the title fix(@angular/build): builder removes @angular/localize when script op… fix(@angular/build): builder removes @angular/localize when script optimization is disabled Nov 7, 2025
@alan-agius4
Copy link
Collaborator

I'm a bit confused by the description of this change. i18n inlining is controlled by the localize option and happens regardless of the optimization setting.

Currently, @angular/localize is already removed only when inlining is required https://github.com/roma-claudio/angular-cli/blob/c3c9ac5067275461e2d8caefba81ac9701949776/packages/angular/build/src/tools/esbuild/application-code-bundle.ts#L674-L675 as otherwise it will be required as a runtime dependency irrespective of the optimization option value.

@roma-claudio
Copy link
Contributor Author

Hi @alan-agius4

Apologies for the misleading reference, at first I thought that I'd check if there are Vite's pre-bundles dependencies (which are not inlined) by looking at the optimized script presence.

Now let me clarify the issue that I've found:

The i18n inliner processes executionResult.outputFiles which from what I've seen do not include Vite's pre-bundled dependencies.
If the polyfills localize is removed, those dependencies which contains $localize will fail to execute.

Ideally, the localize script should only be removed if there are no pre-bundled dependencies containing $localize.
I'm looking for a way to check for this condition before removing or not the import 💭

What do you think?

@alan-agius4
Copy link
Collaborator

Oh I now understand the problem, but for that case, using the optimization option is not the correct approach. In addition as a workaround you could also exclude these deps from bring pre-bundled. Using the dev-server prebundle.exclude option.

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

Kindly sign the CLA as otherwise we'll be unable to accept this change. Also please update the commit message to reflect the change and include a body with a description in the commit.

Thanks.

@alan-agius4 alan-agius4 added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 7, 2025
@roma-claudio roma-claudio force-pushed the fix-polyfills-missing-localize-import branch 2 times, most recently from 700c969 to bf0b1ff Compare November 7, 2025 15:28
@roma-claudio roma-claudio changed the title fix(@angular/build): builder removes @angular/localize when script optimization is disabled fix(@angular/build): builder removes @angular/localize when external packages are not inlined Nov 7, 2025
@roma-claudio roma-claudio marked this pull request as ready for review November 7, 2025 15:29
@roma-claudio
Copy link
Contributor Author

Thanks @alan-agius4

Code updated 👍🏻

…packages are not inlined

The current bundle logic removes any import starting with `@angular/localize` if i18n inline is active.

The i18n inline transformation is only applied to internal packages.

This causes an issue at run time execution of the packages which are external (pre-bundled) and therefore not inlined.

The current fix aims at removing import starting with `@angular/localize` only if both i18n inline is active and there are no external packages.
@roma-claudio roma-claudio force-pushed the fix-polyfills-missing-localize-import branch from bf0b1ff to 48a21b7 Compare November 7, 2025 17:32
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this.

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker merge: squash commits When the PR is merged, a squash and merge should be performed merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 7, 2025
@alan-agius4 alan-agius4 merged commit 38c2200 into angular:main Nov 7, 2025
19 of 35 checks passed
@alan-agius4
Copy link
Collaborator

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

alan-agius4 pushed a commit that referenced this pull request Nov 7, 2025
…ternal packages (#31721)

The current bundle logic removes the `@angular/localize` polyfill if i18n inline is active. However, i18n inlining is not applied on external packages (e.g. during `ng serve` for prebundled dependencies)

This causes an issue at runtime execution of the packages which are external and depend on localization.

With this change the `@angular/localize` polyfill is retained when external packages is truthy.

(cherry picked from commit 38c2200)
alan-agius4 pushed a commit that referenced this pull request Nov 7, 2025
…ternal packages (#31721)

The current bundle logic removes the `@angular/localize` polyfill if i18n inline is active. However, i18n inlining is not applied on external packages (e.g. during `ng serve` for prebundled dependencies)

This causes an issue at runtime execution of the packages which are external and depend on localization.

With this change the `@angular/localize` polyfill is retained when external packages is truthy.

(cherry picked from commit 38c2200)
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 merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed merge: squash commits When the PR is merged, a squash and merge should be performed target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants