Repository navigation
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimearea: i18nIssues related to localization and internationalizationcore: hydrationstate: confirmedstate: has PR
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
Imagine this code:
<div>
@if (currentBreakpoint() === 'mobile') {
<div class="mobile" i18n="@@test">
Mobile content
</div>
} @else {
<div class="desktop" i18n="@@test2">
Desktop content
</div>
}
</div>currentBreakpoint signal can be desktop, mobile or tablet. On server it's always set to 'desktop'.
When i add this little line to my component, hydration breaks and 'desktop' div never cleans up on mobile devices after hydration:
private readonly vcr = inject(ViewContainerRef);Video:
2024-05-24.21.24.22.mov
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 18.0.1
Node: 21.7.3 (Unsupported)
Package Manager: npm 10.5.0
OS: darwin arm64
Angular: 18.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1800.1
@angular-devkit/build-angular 18.0.1
@angular-devkit/core 18.0.1
@angular-devkit/schematics 18.0.1
@angular/cli 18.0.1
@angular/ssr 18.0.1
@schematics/angular 18.0.1
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.6
Warning: The current version of Node (21.7.3) is not supported by Angular.
Anything else?
No response
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimearea: i18nIssues related to localization and internationalizationcore: hydrationstate: confirmedstate: has PR
Activity
JeanMeche commentedon May 24, 2024
You repro doesn't exibit the issue you are describing. Can you double check ?
Did you forgot the
withI18nSupport()initially ? (without it hydration break).AndrewKushnir commentedon May 24, 2024
@zip-fa thanks for providing a repro! As @JeanMeche mentioned, the problem doesn't seem to exist in the code as is, but when I remove
withI18nSupport(), I see the following error:Ideally, when i18n blocks are present, but there is no
withI18nSupport(), hydration should work as it used to work before: components with i18n blocks should skip hydration. We should also consider producing a console warning in a browser for such cases and suggest addingwithI18nSupport()call.Looking at the HTML output, this is likely a culprit:
i.e. the
nghattribute value containsnull, which is likely unexpected and we should look at the serialization code, which appends thenghattribute. I think the fix would be to avoid appendingnghfor those cases (i.e. opt a component out of hydration as it happens prior to v18).cc @devknoll
[-]Broken hydration after v17 -> v18 migration[/-][+]Broken hydration after v17 -> v18 migration if i18n blocks are used[/+]AndrewKushnir commentedon May 24, 2024
More info after some additional investigation: here is a unit test (can be added to the
packages/platform-server/test/hydration_spec.tsfile) that reproduces the issue:The fix would likely be somewhere in the
annotateLContainerForHydrationfunction (code), which would need to account for a case when i18n blocks are present, butwithI18nSupport()function is not invoked (we have similar checks here).zip-fa commentedon May 25, 2024
I am 100% sure that 'desktop' block is not removed on my setup - it stays in the DOM tree after initial page render (on first load) while it must be removed.
Tested on safari and chrome on mac os.
zip-fa commentedon May 25, 2024
Added slower video. When screen blinks, i just refresh the page (cmd+r):
2024-05-25.11.03.12.mov
@if (currentBreakpoint() === 'mobile') successfully becomes true on 'mobile screens', but @else block is not removed from DOM tree only after initial page render when hydration active
JeanMeche commentedon May 25, 2024
This is due to the error thrown during hydration
fix(core): handle missing `withI18nSupport()` call for components tha…
AndrewKushnir commentedon May 30, 2024
@zip-fa FYI, I've created PR #56175 with the fix for the issue described in #56074 (comment). The PR will go through the regular review and testing phases and will be included into one of the next 18.0.x releases. Thank you.
fix(core): handle missing `withI18nSupport()` call for components tha…
fix(core): handle missing `withI18nSupport()` call for components tha…
angular-automatic-lock-bot commentedon Jun 30, 2024
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.