fix(nuxt): don't mark redirected routes as prerendered (#23707)

This commit is contained in:
Daniel Roe 2023-10-16 23:28:42 +01:00 committed by GitHub
parent 00917a1bd8
commit ae630c599f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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",

View File

@ -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()
})
})