-
-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic content in locale file is loaded in SSR then reloaded on the client during hydration #663
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 We could potentially treat those two cases differently but not sure... Are you exporting plain object or function from your language files? |
I am exporting a plain object but I populate some of it using function calls. For example
The issue is/was that the But this just solves the visual problem of the text changing, it doesn't alter the fact that the hydration step still re-runs the translation file. I could see more elaborate translation setups being rather costly to re-run. |
The fix would work for that (object) case, but for functions, we would need to handle them as we do now - processing them separately for client/server. I think I'm fine with that. Just might be difficult to explain that difference in the docs for people to understand it really. |
Couldn't a flag in the store be set indicating that the function had already been called server-side and not to call it again client-side? |
Current functionality passes Nuxt Also, your suggestion to have a store state for that: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Instead of client importing and processing messages (translations) itself on load pass already loaded messages from the server through nuxtState. This will in most cases allow avoiding triggering an extra network request to fetch lang file for given locale. Slight behavior change: The client will no longer import the lang file itself for the initially used locale. That means that if the lang file has exported a function, it will only be called on the server and not the client. This matches behavior of "asyncData" and I think it makes more sense in general. Resolves #486 Resolves #663
With #823 we'll load translations on the server and pass that to the client so extra network requests (combined with #820) will be completely avoided. Contrary to what I've said before, this will also work for lang files that export a function. I've decided to change behavior of those a bit so that if those were processed on the server, we'll not process them again on the client. That matches asyncData so I think it makes sense. |
Instead of client importing and processing messages (translations) itself on load, pass already loaded messages from the server through "nuxtState". This will in most cases allow avoiding triggering an extra network request to fetch lang file for the given locale. Slight behavior change: The client will no longer import the lang file itself for the initially used locale. That means that if the lang file has exported a function, it will only be called on the server and not on the client. This matches behavior of "asyncData" and I think it makes more sense in general. Resolves #486 Resolves #663
Released in v6.13.3 |
Version
v6.8.1
Reproduction link
https://none
Steps to reproduce
lazy: true
in nuxt.config.js./locales/en.js
message: Math.random()
translation{{ $t('message') }}
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.
The text was updated successfully, but these errors were encountered: