mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-22 16:39:58 +00:00
Compare commits
6 Commits
bd2df9413c
...
9c096a4a10
Author | SHA1 | Date | |
---|---|---|---|
|
9c096a4a10 | ||
|
66c3549e1e | ||
|
56a84a1fe4 | ||
|
ce6d3c1b9e | ||
|
a3c63cd9d6 | ||
|
b3d5c9836e |
@ -9,12 +9,10 @@ import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
||||
export default defineNuxtPlugin({
|
||||
name: 'nuxt:payload',
|
||||
setup (nuxtApp) {
|
||||
// TODO: Support dev
|
||||
if (import.meta.dev) { return }
|
||||
|
||||
// Load payload after middleware & once final route is resolved
|
||||
useRouter().beforeResolve(async (to, from) => {
|
||||
if (to.path === from.path) { return }
|
||||
// Forcefully load payload in dev mode, to support payload extraction at page refresh.
|
||||
if (to.path === from.path && !import.meta.dev) { return }
|
||||
const payload = await loadPayload(to.path)
|
||||
if (!payload) { return }
|
||||
Object.assign(nuxtApp.static.data, payload.data)
|
||||
|
@ -659,7 +659,7 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
}
|
||||
|
||||
// Add prerender payload support
|
||||
if (!nuxt.options.dev && nuxt.options.experimental.payloadExtraction) {
|
||||
if (nuxt.options.experimental.payloadExtraction) {
|
||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
||||
}
|
||||
|
||||
@ -779,10 +779,6 @@ export default defineNuxtPlugin({
|
||||
nitro.options.replace['process.env.NUXT_PAYLOAD_EXTRACTION'] = String(!!nuxt.options.experimental.payloadExtraction)
|
||||
nitro.options._config.replace!['process.env.NUXT_PAYLOAD_EXTRACTION'] = String(!!nuxt.options.experimental.payloadExtraction)
|
||||
|
||||
if (!nuxt.options.dev && nuxt.options.experimental.payloadExtraction) {
|
||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
||||
}
|
||||
|
||||
// Show compatibility version banner when Nuxt is running with a compatibility version
|
||||
// that is different from the current major version
|
||||
if (!(satisfies(nuxt._version, nuxt.options.future.compatibilityVersion + '.x'))) {
|
||||
|
@ -325,7 +325,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
// Whether we are prerendering route
|
||||
const _PAYLOAD_EXTRACTION = import.meta.prerender && process.env.NUXT_PAYLOAD_EXTRACTION && !ssrContext.noSSR && !isRenderingIsland
|
||||
const payloadURL = _PAYLOAD_EXTRACTION ? joinURL(ssrContext.runtimeConfig.app.cdnURL || ssrContext.runtimeConfig.app.baseURL, url, process.env.NUXT_JSON_PAYLOADS ? '_payload.json' : '_payload.js') + '?' + ssrContext.runtimeConfig.app.buildId : undefined
|
||||
if (import.meta.prerender) {
|
||||
|
||||
const pagePrerenderedInDev = import.meta.dev && (!!routeOptions.prerender || isRenderingPayload)
|
||||
if (pagePrerenderedInDev || import.meta.prerender) {
|
||||
ssrContext.payload.prerenderedAt = Date.now()
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,6 @@ describe('resolveApp', () => {
|
||||
},
|
||||
],
|
||||
"plugins": [
|
||||
{
|
||||
"mode": "client",
|
||||
"src": "<repoRoot>/packages/nuxt/src/app/plugins/payload.client.ts",
|
||||
},
|
||||
{
|
||||
"mode": "client",
|
||||
"src": "<repoRoot>/packages/nuxt/src/app/plugins/navigation-repaint.client.ts",
|
||||
@ -63,6 +59,10 @@ describe('resolveApp', () => {
|
||||
"mode": "client",
|
||||
"src": "<repoRoot>/packages/nuxt/src/app/plugins/chunk-reload.client.ts",
|
||||
},
|
||||
{
|
||||
"mode": "client",
|
||||
"src": "<repoRoot>/packages/nuxt/src/app/plugins/payload.client.ts",
|
||||
},
|
||||
{
|
||||
"filename": "components.plugin.mjs",
|
||||
"getContents": [Function],
|
||||
|
Loading…
Reference in New Issue
Block a user