Static GitHub Issues

[972] Server state restore is executed after Vuex plugins

prev: How to use `nuxtServerInit` with `nuxt generate`?
next: Route's hash part cannot be passed to server via middleware or fetch

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()
]
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c841">#c841</a>)</em></sub></div>