fix(vue-app): prevent double layout execution (#5703) (#7442)

This commit is contained in:
Jonas Galvez 2020-06-09 13:39:51 -03:00 committed by GitHub
parent cbbf6652cd
commit 0acfc78932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -595,13 +595,8 @@ function normalizeComponents (to, ___) {
}) })
} }
function showNextPage (to) { <% if (features.layouts) { %>
// Hide error component if no error function setLayoutForNextPage (to) {
if (this._hadError && this._dateLastError === this.$options.nuxt.dateErr) {
this.error()
}
<% if (features.layouts) { %>
// Set layout // Set layout
let layout = this.$options.nuxt.err let layout = this.$options.nuxt.err
? (NuxtError.options || NuxtError).layout ? (NuxtError.options || NuxtError).layout
@ -611,7 +606,14 @@ function showNextPage (to) {
layout = layout(app.context) layout = layout(app.context)
} }
this.setLayout(layout) this.setLayout(layout)
<% } %> }
<% } %>
function checkForErrors (app) {
// Hide error component if no error
if (app._hadError && app._dateLastError === app.$options.nuxt.dateErr) {
app.error()
}
} }
// When navigating on a different route but the same component is used, Vue.js // When navigating on a different route but the same component is used, Vue.js
@ -647,7 +649,7 @@ function fixPrepatch (to, ___) {
}) })
} }
}) })
showNextPage.call(this, to) checkForErrors(this)
<% if (isDev) { %> <% if (isDev) { %>
// Hot reloading // Hot reloading
setTimeout(() => hotReloadAPI(this), 100) setTimeout(() => hotReloadAPI(this), 100)
@ -826,6 +828,9 @@ async function mountApp (__app) {
// Add afterEach router hooks // Add afterEach router hooks
router.afterEach(normalizeComponents) router.afterEach(normalizeComponents)
<% if (features.layouts) { %>
router.afterEach(setLayoutForNextPage.bind(_app))
<% } %>
router.afterEach(fixPrepatch.bind(_app)) router.afterEach(fixPrepatch.bind(_app))
// Listen for first Vue update // Listen for first Vue update
@ -874,7 +879,8 @@ async function mountApp (__app) {
// First render on client-side // First render on client-side
const clientFirstMount = () => { const clientFirstMount = () => {
normalizeComponents(router.currentRoute, router.currentRoute) normalizeComponents(router.currentRoute, router.currentRoute)
showNextPage.call(_app, router.currentRoute) setLayoutForNextPage.call(_app, router.currentRoute)
checkForErrors(_app)
// Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render // Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render
mount() mount()
} }