-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
useSSR doesn't change language server side #823
Comments
Do you use the same instance of i18next on serverside render do you not use the i18n instance that you get from req.i18n using the express middleware? |
I use my own instance indeed. I didn't thought the middleware will give me a new one each time. To have the full context, here is the gist of my Next / i18next HoC. https://gist.github.com/Swiip/457f50cb4c4da0698f39cc06db2cad9e |
using that is crucial -> as think of two requests doing async operations before doing send the response both use your one singleton i18next instance and change the language on it...you will get wrong responses. for react-i18next + next.js i highly recommend: https://github.com/isaachinman/next-i18next |
Thanks for the hint. I don't want to use the full next-i18next which is too much for me but understanding the question of using different instances of i18next on the server side let me fix my problems. It's fully working now. If I may ask yet something else, using specific instances of i18next creates the need of accessing the instance in the context. react-i18next doesn't publish its context and I was not able to get back to it to programmatically ask for changing language. I doubled with my own context but it's a shame, if you can just export the context linked to the provider, it would be enough. |
exposing https://github.com/i18next/react-i18next/blob/master/src/context.js#L17 here https://github.com/i18next/react-i18next/blob/master/src/index.js#L9 would be enough.... Would you like to provide a PR? |
Yep, exactly, I will send the PR |
Describe the bug
Using
useSSR
with Next. I cache user language selection with a cookie. The server always use the same language server side which leads to hydration problems.Linked to #671 and probably #817
Looking at the code of
useSSR
, it seems that the use ofi18n.initializedLanguageOnce
prevent to change language. It's ok client side but server side, the same server with the same instance of i18next will be reused to handle requests asking with different languages.Occurs in react-i18next version
10.1.1
To Reproduce
Expected behaviour
useSSR
server side should be able to respond with the detected language, not keeping the first language usedOS (please complete the following information):
Additional context
I have a workaround waiting for a more elegant solution.
The text was updated successfully, but these errors were encountered: