From 4034801fc9f6d79b13568b2137602b52dbfd3b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Fri, 24 Mar 2017 01:35:57 +0100 Subject: [PATCH] Replace store state the soonest possible --- lib/app/client.js | 6 ------ lib/app/index.js | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index 8f8eee1d3c..d5fdba931b 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -336,12 +336,6 @@ const NUXT = window.__NUXT__ || {} if (!NUXT) { throw new Error('[nuxt.js] cannot find the global variable __NUXT__, make sure the server is working.') } -<% if (store) { %> -// Replace store state -if (NUXT.state) { - store.replaceState(NUXT.state) -} -<% } %> // Get matched components const path = getLocation(router.options.base) const resolveComponents = flatMapComponents(router.match(path), (Component, _, match, key, index) => { diff --git a/lib/app/index.js b/lib/app/index.js index dd14678474..45040673e1 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -26,6 +26,12 @@ Vue.use(Meta, { }) if (process.browser) { + <% if (store) { %> + // Replace store state before calling plugins + if (window.__NUXT__ && window.__NUXT__.state) { + store.replaceState(window.__NUXT__.state) + } + <% } %> // window.onNuxtReady(() => console.log('Ready')) hook // Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) window._nuxtReadyCbs = []