-
-
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
Fix state not defined issue in #173 #178
Fix state not defined issue in #173 #178
Conversation
I would like to note, that #173 occures even when the SSR is not meant at all, i.e. in SPA nuxt mode. |
@priezz You are correct. This is not unique to SSR. It's how Vuex implements preserveState option. When preserveState is set to true, it skips adding state for the module since it assumes the state value already exists, as it can be passed from SSR. Here's the explanation about Vuex preserveState; vuejs/vuex#1130 (comment) |
Hi and thanks for the PR! Sorry for the delay in checking the PR. |
@paulgv Sorry for the late response. TLDR: it works for both cases. The plugin became broken due to a Nuxt change mentioned in one of the issues you posted here: nuxt/nuxt#3757 (comment). Nuxt now overrides the store.registerModule method for universal apps after this PR https://github.com/nuxt/nuxt.js/pull/3909/files#diff-c1b82c7b8931d52d83e399952282cbc2R52 When preserveState is set to false, it simply initiates with local state. Since this module doesn't have any default server-rendered state, it should work fine in either case. The reason @priezz is having this issue even when SSR is not being used is very likely due to the mode is set to universal. Pls let me know if this is not correct. This problem was also identified on Nuxt repo: nuxt/nuxt#4370 |
@michaelize Mode is set to 'spa' in my case. |
@priezz I couldn't reproduce this issue under spa mode. Can you create a sample repo? |
This PR fixes #173
The problem occurs when deploying with SSR to a static host, such as AWS S3, then access
https://example.com/en
. Since there is no matching file, Nuxt loads the fallback filehttps://example.com/200.html
.Now due to there is no server rendered state value defined(https://nuxtjs.org/guide/vuex-store#modules-mode), client preserves the state without the i18n module state, which raised an exception later when trying to set the locale.
The fix is to set
{ preserveState: false }
by default. If need to pass value from the server, then setpreserveState
to true in the options, and create a module vuex file as described here: https://nuxtjs.org/guide/vuex-store#modules-mode