Static GitHub Issues

[428] store initialization in plugin

prev: axios plugin
next: $nuxt.$on('routeChanged') stops firing

it appears there is some asynchronous activity happening with loading the SSR state into the store. In my sentry/raven plugin, I need to set UserContext with the store. However, due to some delay on the store being available after import store from ~store, access to the store immediately after results in a null state.

I was able to work around this by accessing the state from within the window.onNuxtReady callback but I soon ran into another issue. In the case of sentry, if an error occurs during initializing of nuxt, the user context is lost - as this is set post nuxt being ready.

The last workaround was reading directly from window.__NUXT__.state. This is what I'm sticking to now. Would like to hear your thoughts on if this is wrong and why the ~store seems to not be immediately synced to the window.NUXT.state when imported.

sentry.js: setUserContext

if (window.__NUXT__.state.current_user) {
  Raven.setUserContext( window.__NUXT__.state.current_user )
}
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This feature request is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c372">#c372</a>)</em></sub></div>