fix(vue-app): static payload fetching bugfixes (#8701)

This commit is contained in:
pooya parsa 2021-01-27 11:26:34 +01:00 committed by GitHub
parent dc551f9709
commit febd7ee43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -324,22 +324,22 @@ export default {
this._pagePayload = payload
this._fetchCounters = {}
},
async fetchPayload(route) {
async fetchPayload(route, prefetch) {
<% if (nuxtOptions.generate.manifest) { %>
const manifest = await this.fetchStaticManifest()
const path = this.getRoutePath(route)
if (!manifest.routes.includes(path)) {
this.setPagePayload(false)
if (!prefetch) { this.setPagePayload(false) }
throw new Error(`Route ${path} is not pre-rendered`)
}
<% } %>
const src = urlJoin(this.getStaticAssetsPath(route), 'payload.js')
try {
const payload = await window.__NUXT_IMPORT__(decodeURI(route), encodeURI(src))
this.setPagePayload(payload)
if (!prefetch) { this.setPagePayload(payload) }
return payload
} catch (err) {
this.setPagePayload(false)
if (!prefetch) { this.setPagePayload(false) }
throw err
}
}

View File

@ -21,7 +21,9 @@ import {
import { createApp<% if (features.layouts) { %>, NuxtError<% } %> } from './index.js'
<% if (features.fetch) { %>import fetchMixin from './mixins/fetch.client'<% } %>
import NuxtLink from './components/nuxt-link.<%= features.clientPrefetch ? "client" : "server" %>.js' // should be included after ./index.js
<% if (isFullStatic) { %>import './jsonp'<% } %>
<% if (isFullStatic) { %>import { installJsonp } from './jsonp'<% } %>
<% if (isFullStatic) { %>installJsonp()<% } %>
<% if (features.fetch) { %>
// Fetch mixin

View File

@ -112,7 +112,7 @@ export default {
if (!this.$root.isPreview) {
const { href } = this.$router.resolve(this.to, this.$route, this.append)
if (this.<%= globals.nuxt %>)
this.<%= globals.nuxt %>.fetchPayload(href).catch(() => {})
this.<%= globals.nuxt %>.fetchPayload(href, true).catch(() => {})
}
<% } %>
<% if (router.linkPrefetchedClass) { %>

View File

@ -75,6 +75,9 @@ function importChunk(chunkId, src) {
return promise
}
window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
window.__NUXT_JSONP_CACHE__ = chunks
window.__NUXT_IMPORT__ = importChunk
export function installJsonp() {
window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
window.__NUXT_JSONP_CACHE__ = chunks
window.__NUXT_IMPORT__ = importChunk
}