nuxt: NuxtServerInit may be have a major problem

Have a code

nuxtServerInit({ commit }){
    commit('setNumber', Math.random());
}

If there are two people at the same time online Suppose they get 0.1 and 0.2 on the server But they get the same value on the browser When they use {{ number }} They will show the same value That is to compare the later one

<div align="right">This question is available on Nuxt.js community (#c2179)</div>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (7 by maintainers)

Most upvoted comments

We are also facing the same issue. Server side the data is correct. But on client side, identical data is showing up for different users. Request you to please fix this at the earliest.

@msahajwani Does your ./state export a object ? If so, you can change it to a function, such as:

// state.js
export default () => ({
    authUser: null
})

//store.js
import Vuex from 'vuex'
import createState from './state'
import mutations from './mutations'
import actions from './actions/'
import getters from './getters'

const store = () => {
  const vuexStore = new Vuex.Store({
    createState(),
    mutations,
    actions,
    getters
  })

  // @TODO: Development
  if (process.browser) {
    window.store = vuexStore
  }
  return vuexStore
}

export default store

@clarkdo The code steps are no problem You have to print the data on the client side

mounted(){
    alert(this.authUser); // or console.log(this.authUser) or {{ authUser}} in template
}

Then let two people connect at the same time ( wait ten seconds should be within ten seconds ) Maybe can reproduce my problem You will get two different data on the server side You will gett wo identical data on the client side ( browser )

Please confirm to see if you can reproduce this problem