Repository navigation
Closed as not planned
Labels
area: coreIssues related to the framework runtimecore: hydrationneeds reproductionThis issue needs a reproduction in order for the team to investigate further
Milestone
Description
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
I have basic development & production configuration like below,
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "3mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kb",
"maximumError": "1mb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
},
"scripts": {
"ng": "ng",
"start": "ng serve --port=4444 -o",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"serve:ssr:ser_test": "node dist/srr_test/server/server.mjs"
},
It seems like when you run npm run build followed by npm run serve:ssr:ser_test, hydration isn't functioning properly, evidenced by flickering. However, in development mode (npm run start), the flickering issue is less pronounced, although still present.
Moving the configurations below into the production config:
"optimization": false,
"extractLicenses": false,
"sourceMap": true
resolves the hydration issue in the production build. It appears that the optimization flag might be the culprit, as enabling it causes the issue to resurface. Despite the hydration not fully working, it's crucial to address this issue. Could there be something overlooked in this setup?
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 17.1.0
Node: 21.4.0 (Unsupported)
Package Manager: npm 10.2.4
OS: darwin arm64
Angular: 17.1.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... platform-server, router, ssr
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1701.0
@angular-devkit/build-angular 17.1.0
@angular-devkit/core 17.1.0
@angular-devkit/schematics 17.1.0
@schematics/angular 17.1.0
rxjs 7.8.1
typescript 5.2.2
zone.js 0.14.3
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimecore: hydrationneeds reproductionThis issue needs a reproduction in order for the team to investigate further
Activity
AndrewKushnir commentedon Feb 17, 2024
@princ09 unfortunately, the information that you provided is not sufficient to perform further investigation, but here are a couple things that you can check:
provideClientHydration()call is present in the app config), see here for additional info. Based on the description of the problem (the flickering behavior), I suspect that this might be the case.If the problem still exists, please create a minimal repro (only relevant code and minimal possible setup, please do not share the whole app) in a form of GitHub repository, so that we can perform further investigation.
princ09 commentedon Feb 17, 2024
@AndrewKushnir
I already have followed everything mentioned in the docs, Please refer below,
In fact I am getting this message in console as well,
Angular hydrated 17 component(s) and 158 node(s), 0 component(s) were skipped. Learn more at https://angular.io/guide/hydration.
Please see the recording of how it's flickering ,
screen-capture.webm
Let me know If I am missing something,
Thanks
AndrewKushnir commentedon Feb 17, 2024
@princ09 thanks for providing more info. Based on the console message, hydration was enabled and actually worked. Based on the screen recording - this flickering happens due to the external font loading delay. The solution would be to optimize font loading (use a smaller font, add preconnect/preload tags, etc).
Unrelated to font loading, but you can also drop
initialNavigation: 'enabledBlocking'- that is no longer required when hydration is enabled.princ09 commentedon Feb 19, 2024
@AndrewKushnir Thank you for your reply. After removing the font-display property it solved the font issue but the hydration issue is still there. I have created a git repo for you here. I have enabled hydration.

See in screenshot, I got the message as well,
But still flickering issue is there, please check the video
screen-capture (2).webm
AndrewKushnir commentedon Feb 20, 2024
@princ09 thanks for additional info and creating a repro.
I took a look and found out that hydration works correctly - most of the nodes on a page got hydrated (vs being re-created from scratch).
I've also noticed that navigating to a different page in your test app causes a full page reload. As a possible option to improve the navigation experience, you can try to use view transitions feature. You can enable it by doing this change:
You can also try using the
RouterLinkdirective to enable client navigations (without a full page reload) to see if that works better for you. Here is a diff that I've made to use theRouterLinkfor the Home and About links (so you can navigate between those pages to test the behavior):Based on the investigation results, it looks like hydration works as expected and there are no action items for the framework, so I'll close the ticket for now. Please reopen or create a new one if you come across an issue caused by the framework logic.
princ09 commentedon Mar 11, 2024
Sorry @AndrewKushnir, I wasn't available for the last few weeks. Unfortunately, this solution is not a solution in my perspective because of two reasons.
Please have look into this amazing ssr website Dhan.co , here every link is href and whole page get rendered from server. I believe they used react with next.js, I am looking for similiar result from angular 17.
AndrewKushnir commentedon Mar 11, 2024
@princ09 thanks for additional info. You don't have to use
routerLink, the hydration works on your demo correctly after a page refresh.You can still try to use
withViewTransitions()as described above to improve transitions between pages.angular-automatic-lock-bot commentedon Apr 11, 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.