Skip to content

Commit fa323db

Browse files
committed
fix(nitro): keep noScripts wildcard patterns single-segment
1 parent a5a6a1e commit fa323db

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/nitro-server/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export async function bundle (nuxt: Nuxt & { _nitro?: Nitro }): Promise<void> {
242242
// to them.
243243
const noScriptsPatterns = [...new Set(Object.entries(nitro.options.routeRules)
244244
.filter(([_route, rules]) => rules.noScripts)
245-
.map(([route]) => rou3PatternToURLPattern(route).pattern))]
245+
.map(([route]) => rou3PatternToURLPattern(route, { wildcard: 'segment' }).pattern))]
246246
// `href_matches` patterns for every page route, provided by the pages
247247
// module; pages served without scripts scope their blanket speculation
248248
// rules to these (safe-to-GET) same-origin navigations

‎packages/nitro-server/test/nitro-config.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ async function isInlined (nitro: Nitro, id: string) {
4747
}
4848

4949
describe('nitro config', () => {
50+
it('emits valid single-segment URLPatterns for noScripts wildcard rules', async () => {
51+
await withNitro({ routeRules: { '/foo/*': { noScripts: true }, '/scripted/*': { ssr: true } } }, async (_nitro, nitroConfig) => {
52+
const rendererConfig = nitroConfig.virtual!['nuxt/internal/renderer-config'] as () => Promise<string>
53+
const code = await rendererConfig()
54+
const patterns: string[] = JSON.parse(/^export const NUXT_NO_SCRIPTS_PATTERNS = (.+)$/m.exec(code)![1]!)
55+
56+
expect(patterns).toEqual(['/foo/([^\\/]*)'])
57+
const pattern = new URLPattern({ pathname: patterns[0] })
58+
expect(pattern.test('https://example.com/foo/bar')).toBe(true)
59+
expect(pattern.test('https://example.com/foo/bar/baz')).toBe(false)
60+
expect(pattern.test('https://example.com/scripted/bar')).toBe(false)
61+
})
62+
}, 60_000)
63+
5064
it('passes the server replacements to nitro as `replace`', async () => {
5165
await withNitro({}, (_nitro, nitroConfig) => {
5266
expect(nitroConfig.replace).toMatchObject(serverReplacements)

0 commit comments

Comments
 (0)