Dynamic content in locale file is loaded in SSR then reloaded on the client during hydration
See original GitHub issueVersion
Reproduction link
Steps to reproduce
- Enable
lazy: true
in nuxt.config.js. - Create an
/locales/en.js
- In the en.js file, add a
message: Math.random()
translation - In a template, display
{{ $t('message') }}
- Reload the browser
- Observe the page loads with the translations already applied in SSR, showing a random number
- Observe that a few moments later, hydration happens and the random number is replaced with a new number
What is expected ?
Only the SSR version of the translations would be applied and hydration would not actually update the translations.
What is actually happening?
Hydration is updating the translations, changing the content from what SSR generates.
Additional comments?
The reason this came up is we’re using a lorem ipsum module to quickly mock up fake content in our translations. Having the content change suddenly after first load is jarring.
<div align="right">This bug report is available on Nuxt community (#c436)</div>Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Dynamic content in locale file is loaded in SSR then reloaded ...
Only the SSR version of the translations would be applied and hydration would not actually update the translations. What is actually happening?
Read more >Localized Server-Side Rendering with React | Phrase
Learn here how to localize a React app made with SSR. ... on the server side, and then hydrated on the client side...
Read more >Web Components in Server-Side Rendered (SSR) and Static ...
All the client has to do is hydrate the components and make them functional. The less dynamic content the client renders, the better...
Read more >React 18: Hydration failed because the initial UI does not ...
I have been experiencing the same problem lately with NextJS and i am not sure if my observations are applicable to other libraries....
Read more >Fixing Gatsby's rehydration issue - LogRocket Blog
This post shows you how to overcome a rehydration issue when using server side rendering in Gatsby to makes ure your application runs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It sounds like a good idea and might be a good base for fixing some other issues.
There is something that makes it non-trivial though - language files can export function in which case we have to pass
context
object to them and we can’t do that if we are gonna process those when Nuxt module’s code runs (which we would have to do to fix this).We could potentially treat those two cases differently but not sure…
Are you exporting plain object or function from your language files?
Released in v6.13.3