diff --git a/lib/app/index.js b/lib/app/index.js
index 686608f97b..7b9873743d 100644
--- a/lib/app/index.js
+++ b/lib/app/index.js
@@ -49,6 +49,11 @@ async function createApp (ssrContext) {
const store = createStore(ssrContext)
// Add this.$router into store actions/mutations
store.$router = router
+ <% if (mode === 'universal') { %>
+ // Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141
+ const registerModule = store.registerModule
+ store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.browser }, options))
+ <% } %>
<% } %>
// Create Root instance
diff --git a/test/e2e/basic.browser.test.js b/test/e2e/basic.browser.test.js
index 86442cceee..a5008c7d30 100644
--- a/test/e2e/basic.browser.test.js
+++ b/test/e2e/basic.browser.test.js
@@ -50,6 +50,11 @@ describe('basic browser', () => {
expect(await page.$text('h1')).toBe('My component!')
})
+ test('/store-module', async () => {
+ await page.nuxt.navigate('/store-module')
+ expect(await page.$text('h1')).toBe('mutated')
+ })
+
test('/css', async () => {
await page.nuxt.navigate('/css')
diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js
index 1abd93fded..8223e006d1 100644
--- a/test/fixtures/basic/nuxt.config.js
+++ b/test/fixtures/basic/nuxt.config.js
@@ -8,6 +8,9 @@ export default {
maxAge: ((60 * 60 * 24 * 365) * 2)
}
},
+ plugins: [
+ '~/plugins/vuex-module'
+ ],
router: {
extendRoutes(routes, resolve) {
return [{
@@ -28,7 +31,7 @@ export default {
'/async-data',
'/validate',
'/redirect',
-
+ '/store-module',
'/users/1',
'/users/2',
{ route: '/users/3', payload: { id: 3000 } }
diff --git a/test/fixtures/basic/pages/store-module.vue b/test/fixtures/basic/pages/store-module.vue
new file mode 100644
index 0000000000..bae0b6822f
--- /dev/null
+++ b/test/fixtures/basic/pages/store-module.vue
@@ -0,0 +1,11 @@
+
+ {{ $store.state.simpleModule.mutateMe }}
+
+
+
diff --git a/test/fixtures/basic/plugins/vuex-module.js b/test/fixtures/basic/plugins/vuex-module.js
new file mode 100644
index 0000000000..7dac494a31
--- /dev/null
+++ b/test/fixtures/basic/plugins/vuex-module.js
@@ -0,0 +1,18 @@
+export default function ({ store }) {
+ store.registerModule('simpleModule', {
+ namespaced: true,
+ state: () => ({
+ mutateMe: 'not mutated'
+ }),
+ actions: {
+ mutate({ commit }) {
+ commit('mutate')
+ }
+ },
+ mutations: {
+ mutate(state) {
+ state.mutateMe = 'mutated'
+ }
+ }
+ })
+}
diff --git a/test/unit/basic.generate.test.js b/test/unit/basic.generate.test.js
index 0b9340dc98..8d5c7ea273 100644
--- a/test/unit/basic.generate.test.js
+++ b/test/unit/basic.generate.test.js
@@ -89,6 +89,12 @@ describe('basic generate', () => {
expect(html.includes('