-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
first time translating does not work using switchLocalePath() #378
Comments
That seems to be due to not getting |
@rchl Thanks for the reply. I have the same problem if I test my project locally.
The app behaves the same locally as on Netlify, i.e. the bug described above. |
That would explain it. Statically generated page can't respond with a cookie header. It will only work when running on a node server. I don't have time to look into it more now, I guess it might be fixable in some way and if not, it should be documented better. |
@rchl Thanks for the reply, it gave me an idea for a quick fix in my case.
Can you point me to the code regarding the cookie header, maybe I can have a look at the problem? |
The very initial load of the page sets the cookie here https://github.com/nuxt-community/nuxt-i18n/blob/5aeab8bd7f4b05ce3b05558eedf1150f58c19514/src/templates/middleware.js#L117 But I think middlewares are only ran on generating pages so the code has no chance of triggering when loading static pages... |
this fixed a big issue with memory leakage for me too. |
This bug is caused by Nuxt not invoking middleware for initial request (see this comment for more info: nuxt/rfcs#28 (comment)). It can most likely be worked around by moving some part of the code to the |
@rchl Thanks again for having looked at the bug I was having! |
When generating static files with `nuxt generate` (with default `universal` mode), initial load of the URL doesn't trigger middleware. Nuxt triggers middleware in those cases for initial load: - universal (server: yes, client: no) - spa (server: --, client: yes) - universal+generate (server: --, client: no) - spa+generate (server: --, client: yes) Due to middleware not triggering on initial load, browser language wasn't detected and cookie was not set, which later caused failure to update locale on navigating to route from other locale. That's because detection happened on second navigation and overridden target route's locale. To fix, trigger language detection from the plugin first. For some cases that means that middleware will attempt to trigger detection again but it will be short-cut early as cookie will already be there or target locale will already be set. Also cleaned up some imports and unused variables in middleware and plugin (more cleanup is possible). Resolves #378
that kind of settings worked for me:
|
i am facing this issue, may i know how to fix this? Thanks |
@supakornkim Also have this problem, if you have found the solution, please let me know. Thank you |
Version
v6.0.0
Reproduction link
https://github.com/miteyema/nuxt-i18n-demo
Steps to reproduce
What is expected ?
What is actually happening?
Additional comments?
Please see the following GIF below to see the problem in action:
The text was updated successfully, but these errors were encountered: