From 6d904663a4d0edad8208333e919907087aabac21 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 9 Oct 2022 15:22:19 +0100 Subject: [PATCH] fix(nuxt): use correct cache and add baseURL to payload (#7984) --- packages/nuxt/src/app/composables/payload.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/app/composables/payload.ts b/packages/nuxt/src/app/composables/payload.ts index f53d06d7ab..011d6a6938 100644 --- a/packages/nuxt/src/app/composables/payload.ts +++ b/packages/nuxt/src/app/composables/payload.ts @@ -1,6 +1,6 @@ import { parseURL, joinURL } from 'ufo' import { useNuxtApp } from '../nuxt' -import { useHead } from '..' +import { useHead, useRuntimeConfig } from '..' interface LoadPayloadOptions { fresh?: boolean @@ -12,8 +12,8 @@ export function loadPayload (url: string, opts: LoadPayloadOptions = {}) { const payloadURL = _getPayloadURL(url, opts) const nuxtApp = useNuxtApp() const cache = nuxtApp._payloadCache = nuxtApp._payloadCache || {} - if (cache[payloadURL]) { - return cache[payloadURL] + if (cache[url]) { + return cache[url] } cache[url] = _importPayload(payloadURL).then((payload) => { if (!payload) { @@ -42,7 +42,7 @@ function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) { throw new Error('Payload URL cannot contain search params: ' + url) } 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) {