Version
v1.3.0
Page refreshed multiple times, code reported error
Page refreshed multiple times, code reported error
expect the event to work
Could you provide code or a reproduction repo please? :relaxed:
1.4.2
Working on my first Vue project, I have just run into a similar issue.
Oddly, the issue only appears when I use my static app generated with npm run generate
. It works fine when I use npm run dev
.
I investigated it and found the cause in my case. I will explain it in detail so @tansj526 has a chance to potentially track down their own issue.
Firstly, the problem appeared suddenly, so I did the obvious and reverted the changes of my latest commit. And indeed that fixed it. The changes were:
So everything pointed to the added v-if
directive. Indeed, removing the second v-if
directive on either component fixes it.
The special bit about the drawer
variable is that it is initialised with a vuex value:
js
data () {
return {
drawer: !!this.$store.state.drawer.visible
...
So I made it a non-vuex variable:
js
drawer: false
...and again it worked, with both v-if
s present, and with npm run generate
.
Now, I set up a minimal example project, which worked at first.
Then I investigated the remaining bit of difference: vuex-persistedstate
. I am actually persisting drawer.visible
in LocalStorage so that after a page refresh the navigation drawer of my app remembers its state.
So I installed vuex-persistedstate
into my minimal project based on the nuxt starter and added the drawer.visible key:
````js
// nuxt.config.js
plugins: [
{ src: '~/plugins/localStorage.js', ssr: false }
],
// /plugins/localStorage.js as referenced in nuxt.config.js
import createPersistedState from 'vuex-persistedstate'
export default ({store}) => {
createPersistedState({
key: 'vuex',
paths: [
'drawer.visible'
]
})(store)
}
````
And that indeed produces the same root cause:
Now, when I change my nuxt.config.js
from
js
plugins: [
{ src: '~/plugins/localStorage.js', ssr: false }
],
to
js
plugins: [
// { src: '~/plugins/localStorage.js', ssr: false }
],
it all works again, even with npm run generate
, and with both v-if
s present.
Again, please note that none of these oddities occur with npm run dev
in my case.
So my questions to @tansj526 would be, does that ring any bells? Are you using vuex-persistedstate
or some other plugin that could cause a similar effect? Are you using a generated static site?
In summary, the issue only appears in the following edge case:
Albeit a bit long, I hope this will help track down the issue. I have set up a minimal repo for you to play with here:
https://github.com/steinwachs/bugreport-nuxt-vuex-persistedstate
Now do the same without vuex-persistedstate (comment it out as described below)
I was facing the same error after using nuxt generate (and Apollo). In my case a cookie used by Apollo (for log-in) seems to cause the problem.
I have the same issue only on packaged application
I use :
Do you have a workaround ?
Actually, there are 3 workarounds I know when using vuex-persistedstate
and nuxt generate
or nuxt start
:
v-show
instead of v-if
where you use vuex-persistedstate
data<no-ssr>
around the components using vuex-persistedstate
datavuex-persistedstate
plugin like this (my PR for vuex-persistedstate: https://github.com/robinvdvleuten/vuex-persistedstate/pull/170)export default ({ store }) => {
window.onNuxtReady(() => {
createPersistedState({
...
})(store)
})
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Nuxt Version
1.4.2
Issue Description
Working on my first Vue project, I have just run into a similar issue.
Oddly, the issue only appears when I use my static app generated with
npm run generate
. It works fine when I usenpm run dev
.I investigated it and found the cause in my case. I will explain it in detail so @tansj526 has a chance to potentially track down their own issue.
Firstly, the problem appeared suddenly, so I did the obvious and reverted the changes of my latest commit. And indeed that fixed it. The changes were:

So everything pointed to the added
v-if
directive. Indeed, removing the secondv-if
directive on either component fixes it.The special bit about the
drawer
variable is that it is initialised with a vuex value:js data () { return { drawer: !!this.$store.state.drawer.visible ...
So I made it a non-vuex variable:
js drawer: false
...and again it worked, with both
v-if
s present, and withnpm run generate
.More Details
Now, I set up a minimal example project, which worked at first.
Then I investigated the remaining bit of difference:
vuex-persistedstate
. I am actually persistingdrawer.visible
in LocalStorage so that after a page refresh the navigation drawer of my app remembers its state.So I installed
vuex-persistedstate
into my minimal project based on the nuxt starter and added the drawer.visible key:````js
// nuxt.config.js
plugins: [
{ src: '~/plugins/localStorage.js', ssr: false }
],
// /plugins/localStorage.js as referenced in nuxt.config.js
import createPersistedState from 'vuex-persistedstate'
export default ({store}) => {

createPersistedState({
key: 'vuex',
paths: [
'drawer.visible'
]
})(store)
}
````
And that indeed produces the same root cause:
Now, when I change my
nuxt.config.js
fromjs plugins: [ { src: '~/plugins/localStorage.js', ssr: false } ],
to
js plugins: [ // { src: '~/plugins/localStorage.js', ssr: false } ],
it all works again, even with
npm run generate
, and with bothv-if
s present.Again, please note that none of these oddities occur with
npm run dev
in my case.So my questions to @tansj526 would be, does that ring any bells? Are you using
vuex-persistedstate
or some other plugin that could cause a similar effect? Are you using a generated static site?In summary, the issue only appears in the following edge case:
Albeit a bit long, I hope this will help track down the issue. I have set up a minimal repo for you to play with here:
Reproduction Link
https://github.com/steinwachs/bugreport-nuxt-vuex-persistedstate
Reproduction Steps
Now do the same without vuex-persistedstate (comment it out as described below)