From 108b1bdf7285f3863a855e29a4581738c5ad8a6e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 19 Oct 2023 15:24:33 +0100 Subject: [PATCH] fix(nuxt): restore `prerenderedAt` behaviour pending next patch --- packages/nuxt/src/app/composables/payload.ts | 5 ++++- test/bundle.test.ts | 2 +- test/fixtures/basic/nuxt.config.ts | 3 --- test/fixtures/basic/plugins/prerender.server.ts | 4 ++++ 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/basic/plugins/prerender.server.ts diff --git a/packages/nuxt/src/app/composables/payload.ts b/packages/nuxt/src/app/composables/payload.ts index b708f0bcc1..7220a36e53 100644 --- a/packages/nuxt/src/app/composables/payload.ts +++ b/packages/nuxt/src/app/composables/payload.ts @@ -79,7 +79,10 @@ async function _importPayload (payloadURL: string) { export async function isPrerendered (url = useRoute().path) { // Note: Alternative for server is checking x-nitro-prerender header const nuxtApp = useNuxtApp() - if (!appManifest) { return !!nuxtApp.payload.prerenderedAt } + if (nuxtApp.payload.prerenderedAt) { + return true + } + if (!appManifest) { return false } const manifest = await getAppManifest() if (manifest.prerendered.includes(url)) { return true diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 0887888846..ed506c5094 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -19,7 +19,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM for (const outputDir of ['.output', '.output-inline']) { it('default client bundle size', async () => { const clientStats = await analyzeSizes('**/*.js', join(rootDir, outputDir, 'public')) - expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot('"99.1k"') + expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot('"99.2k"') expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` [ "_nuxt/entry.js", diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 5ff07c9e0b..3c1193ad16 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -47,9 +47,6 @@ export default defineNuxtConfig({ } }, routeRules: { - // TODO: update this test - // pretend to be fully prerendered - '/**': { prerender: true }, '/route-rules/spa': { ssr: false }, '/hydration/spa-redirection/**': { ssr: false }, '/no-scripts': { experimentalNoScripts: true } diff --git a/test/fixtures/basic/plugins/prerender.server.ts b/test/fixtures/basic/plugins/prerender.server.ts new file mode 100644 index 0000000000..9eec0f831c --- /dev/null +++ b/test/fixtures/basic/plugins/prerender.server.ts @@ -0,0 +1,4 @@ +export default defineNuxtPlugin((nuxtApp) => { + // Pretend to be prerendered + nuxtApp.payload.prerenderedAt = Date.now() +})