Home

Issue: 428

store initialization in plugin

[issue link]

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 )
}

This feature request is available on Nuxt.js community (#c372)