Home

Issue: 972

Server state restore is executed after Vuex plugins

[issue link]

In index.js, createState() is called first (and plugins are initialized), then the server state is restored.

This effectively disables plugins using Local Storage to persist state (client side data is overriden with SSR data every time). A brief code example is attached below for easier understanding.

I propose to inject a SSR restore plugin at the first of Vuex plugins constructor parameter. This way, SSR restore happens before other plugins.

Code:

import createPersistedState from 'vuex-persistedstate'

export const state = () => ({
  // ... defaults ...
})

export const plugins = [
  createPersistedState()
]

This question is available on Nuxt.js community (#c841)