Skip to content

Angular Hydration for i18n inside router-outlet not working in production build #58713

Closed

Description

@guybenhemo

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

Components with i18n that is being rendered using router, won't hydrate correctly for production build (works great for development build)

Added hydration for i18n views: provideClientHydration(withI18nSupport()),

The Hydration process is trying to match the ids of the components from the server build and the browser build:

const dehydratedView = findMatchingDehydratedView(this._lContainer, componentDef?.id ?? null);

The component id is being calculated from hash of the component build attributes.
One of those attributes is consts attribute.

When building angular server and browser with optimization = true, the consts attribute is different between the server and the browser build,
causing a mismatch of the ids of the same element, which resulting in hydration skipping.

The server build and the client build consts attribute are not the same because in the browser build there is mangling = true, while in the server build the mangling = false

As you can see mangling = false for server build in optimization = true, but true for browser:
https://github.com/angular/angular-cli/blob/2e43ec6654d7b4a068ed3aea87b8f804e4c2c5f0/packages/angular_devkit/build_angular/src/tools/webpack/configs/common.ts#L308

Example of consts attributes difference between the builds, for this i18n div:

<div class="header" i18n="@@About.Header">Header</div>

Server build:
consts:()=>{let i18n_0;return i18n_0="About",[i18n_0,[1,"header"]]}

Browser build:
consts:()=>{let o;return o="About",[o,[1,"header"]]}

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 18.2.12
Node: 22.11.0
Package Manager: npm 10.2.4
OS: darwin arm64

Angular: 18.2.12
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.12
@angular-devkit/build-angular   18.2.12
@angular-devkit/core            18.2.12
@angular-devkit/schematics      18.2.12
@schematics/angular             18.2.12
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.14.10

Anything else?

No response

Activity

  1. added
    area: i18n
    area: core
    on Nov 18, 2024
  2. added this to the needsTriage milestone on Nov 18, 2024
  3. added
    P2
    on Nov 20, 2024
  4. modified the milestones: needsTriage, Backlog on Nov 20, 2024
  5. AndrewKushnir commented on Nov 22, 2024

    @AndrewKushnir
    Contributor

    @guybenhemo thanks for reporting the issue and providing very useful info. I've created PR #58813 with the fix.

  6. added a commit that references this issue on Nov 22, 2024
    84f45ea
  7. added a commit that references this issue on Nov 22, 2024
    834c7c3
  8. angular-automatic-lock-bot commented on Dec 23, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2area: corearea: i18ncore: hydrationstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions