From ae630c599f625ef459a22ae423683dd22df425d5 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 16 Oct 2023 23:28:42 +0100 Subject: [PATCH] fix(nuxt): don't mark redirected routes as prerendered (#23707) --- packages/nuxt/src/app/composables/payload.ts | 2 +- test/bundle.test.ts | 2 +- test/nuxt/composables.test.ts | 29 ++++++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/nuxt/src/app/composables/payload.ts b/packages/nuxt/src/app/composables/payload.ts index 8a3157cc19..7220a36e53 100644 --- a/packages/nuxt/src/app/composables/payload.ts +++ b/packages/nuxt/src/app/composables/payload.ts @@ -88,7 +88,7 @@ export async function isPrerendered (url = useRoute().path) { return true } const rules = await getRouteRules(url) - return !!rules.prerender + return !!rules.prerender && !rules.redirect } let payloadCache: any = null diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 87d2887870..a8d6acbec4 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/nuxt/composables.test.ts b/test/nuxt/composables.test.ts index 9935776ddf..1dea864fdd 100644 --- a/test/nuxt/composables.test.ts +++ b/test/nuxt/composables.test.ts @@ -27,7 +27,15 @@ registerEndpoint('/_nuxt/builds/latest.json', defineEventHandler(() => ({ registerEndpoint('/_nuxt/builds/meta/override.json', defineEventHandler(() => ({ id: 'override', timestamp, - matcher: { static: { '/': null, '/pre': null }, wildcard: { '/pre': { prerender: true } }, dynamic: {} }, + matcher: { + static: { + '/': null, + '/pre': null, + '/pre/test': { redirect: true } + }, + wildcard: { '/pre': { prerender: true } }, + dynamic: {} + }, prerendered: ['/specific-prerendered'] }))) @@ -306,6 +314,9 @@ describe.skipIf(process.env.TEST_MANIFEST === 'manifest-off')('app manifests', ( "static": { "/": null, "/pre": null, + "/pre/test": { + "redirect": true, + }, }, "wildcard": { "/pre": { @@ -320,12 +331,24 @@ describe.skipIf(process.env.TEST_MANIFEST === 'manifest-off')('app manifests', ( `) }) it('getRouteRules', async () => { - const rules = await getRouteRules('/') - expect(rules).toMatchInlineSnapshot('{}') + expect(await getRouteRules('/')).toMatchInlineSnapshot('{}') + expect(await getRouteRules('/pre')).toMatchInlineSnapshot(` + { + "prerender": true, + } + `) + expect(await getRouteRules('/pre/test')).toMatchInlineSnapshot(` + { + "prerender": true, + "redirect": true, + } + `) }) it('isPrerendered', async () => { expect(await isPrerendered('/specific-prerendered')).toBeTruthy() expect(await isPrerendered('/prerendered/test')).toBeTruthy() expect(await isPrerendered('/test')).toBeFalsy() + expect(await isPrerendered('/pre/test')).toBeFalsy() + expect(await isPrerendered('/pre/thing')).toBeTruthy() }) })