fix(vue-app): prevent router.registerModule reallocation (#7915) (#7916)

This commit is contained in:
Jonas Galvez 2020-08-15 17:29:17 -03:00 committed by GitHub
parent 44471ec9df
commit fe0498cecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
<% if (store) { %>import Vuex from 'vuex'<% } %>
<% if (features.meta) { %>import Meta from 'vue-meta'<% } %> <% if (features.meta) { %>import Meta from 'vue-meta'<% } %>
<% if (features.componentClientOnly) { %>import ClientOnly from 'vue-client-only'<% } %> <% if (features.componentClientOnly) { %>import ClientOnly from 'vue-client-only'<% } %>
<% if (features.deprecations) { %>import NoSsr from 'vue-no-ssr'<% } %> <% if (features.deprecations) { %>import NoSsr from 'vue-no-ssr'<% } %>
@ -66,6 +67,15 @@ const defaultTransition = <%=
%><%= isTest ? '// eslint-disable-line' : '' %> %><%= isTest ? '// eslint-disable-line' : '' %>
<% } %> <% } %>
<% if (store) { %>
const originalRegisterModule = Vuex.Store.prototype.registerModule
const baseStoreOptions = { preserveState: process.client }
function registerModule (path, rawModule, options = {}) {
return originalRegisterModule.call(this, path, rawModule, { ...baseStoreOptions, ...options })
}
<% } %>
async function createApp(ssrContext, config = {}) { async function createApp(ssrContext, config = {}) {
const router = await createRouter(ssrContext) const router = await createRouter(ssrContext)
@ -75,8 +85,7 @@ async function createApp(ssrContext, config = {}) {
store.$router = router store.$router = router
<% if (mode === 'universal') { %> <% if (mode === 'universal') { %>
// Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141 // Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141
const registerModule = store.registerModule store.registerModule = registerModule
store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options))
<% } %> <% } %>
<% } %> <% } %>