mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxt): use correct cache and add baseURL to payload (#7984)
This commit is contained in:
parent
e71a59985e
commit
6d904663a4
@ -1,6 +1,6 @@
|
|||||||
import { parseURL, joinURL } from 'ufo'
|
import { parseURL, joinURL } from 'ufo'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { useHead } from '..'
|
import { useHead, useRuntimeConfig } from '..'
|
||||||
|
|
||||||
interface LoadPayloadOptions {
|
interface LoadPayloadOptions {
|
||||||
fresh?: boolean
|
fresh?: boolean
|
||||||
@ -12,8 +12,8 @@ export function loadPayload (url: string, opts: LoadPayloadOptions = {}) {
|
|||||||
const payloadURL = _getPayloadURL(url, opts)
|
const payloadURL = _getPayloadURL(url, opts)
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
const cache = nuxtApp._payloadCache = nuxtApp._payloadCache || {}
|
const cache = nuxtApp._payloadCache = nuxtApp._payloadCache || {}
|
||||||
if (cache[payloadURL]) {
|
if (cache[url]) {
|
||||||
return cache[payloadURL]
|
return cache[url]
|
||||||
}
|
}
|
||||||
cache[url] = _importPayload(payloadURL).then((payload) => {
|
cache[url] = _importPayload(payloadURL).then((payload) => {
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
@ -42,7 +42,7 @@ function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) {
|
|||||||
throw new Error('Payload URL cannot contain search params: ' + url)
|
throw new Error('Payload URL cannot contain search params: ' + url)
|
||||||
}
|
}
|
||||||
const hash = opts.hash || (opts.fresh ? Date.now() : '')
|
const hash = opts.hash || (opts.fresh ? Date.now() : '')
|
||||||
return joinURL(parsed.pathname, hash ? `_payload.${hash}.js` : '_payload.js')
|
return joinURL(useRuntimeConfig().app.baseURL, parsed.pathname, hash ? `_payload.${hash}.js` : '_payload.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _importPayload (payloadURL: string) {
|
async function _importPayload (payloadURL: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user