Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): use correct cache and add baseURL to payload #7984

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/nuxt/src/app/composables/payload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseURL, joinURL } from 'ufo'
import { useNuxtApp } from '../nuxt'
import { useHead } from '..'
import { useHead, useRuntimeConfig } from '..'

interface LoadPayloadOptions {
fresh?: boolean
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down