Skip to content

Commit 3417164

Browse files
authored
Fix index revalidate with dynamic route in minimal mode (#22783)
This fixes the case where index page revalidation would match a dynamic page instead of the index page from the pathname not being denormalized. Fixes: #22750
1 parent 1f5c2c8 commit 3417164

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

packages/next/next-server/server/config-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function shouldLoadWithWebpack5(
5151

5252
export async function loadWebpackHook(phase: string, dir: string) {
5353
let useWebpack5 = false
54-
const worker: any = new Worker(__filename, { enableWorkerThreads: true })
54+
const worker: any = new Worker(__filename, { enableWorkerThreads: false })
5555
try {
5656
useWebpack5 = Boolean(await worker.shouldLoadWithWebpack5(phase, dir))
5757
} catch {

packages/next/next-server/server/next-server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export default class Server {
340340
const { pathname, query } = parsedPath
341341
let matchedPathname = pathname as string
342342

343-
const matchedPathnameNoExt = isDataUrl
343+
let matchedPathnameNoExt = isDataUrl
344344
? matchedPathname.replace(/\.json$/, '')
345345
: matchedPathname
346346

@@ -355,6 +355,11 @@ export default class Server {
355355
}
356356
}
357357

358+
if (isDataUrl) {
359+
matchedPathname = denormalizePagePath(matchedPathname)
360+
matchedPathnameNoExt = denormalizePagePath(matchedPathnameNoExt)
361+
}
362+
358363
const pageIsDynamic = isDynamicRoute(matchedPathnameNoExt)
359364
const utils = getUtils({
360365
pageIsDynamic,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const getStaticProps = () => {
2+
return {
3+
props: {
4+
hello: 'world',
5+
},
6+
}
7+
}
8+
9+
export const getStaticPaths = () => {
10+
return {
11+
paths: [],
12+
fallback: true,
13+
}
14+
}
15+
16+
export default function Page(props) {
17+
return <p id="slug-page">[slug] page</p>
18+
}

test/integration/required-server-files/test/index.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,30 @@ describe('Required Server Files', () => {
508508
expect(json.query).toEqual({ another: 'value' })
509509
expect(json.url).toBe('/api/optional?another=value')
510510
})
511+
512+
it('should match the index page correctly', async () => {
513+
const res = await fetchViaHTTP(appPort, '/', undefined, {
514+
headers: {
515+
'x-matched-path': '/index',
516+
},
517+
redirect: 'manual',
518+
})
519+
520+
const html = await res.text()
521+
const $ = cheerio.load(html)
522+
expect($('#index').text()).toBe('index page')
523+
})
524+
525+
it('should match the root dyanmic page correctly', async () => {
526+
const res = await fetchViaHTTP(appPort, '/index', undefined, {
527+
headers: {
528+
'x-matched-path': '/[slug]',
529+
},
530+
redirect: 'manual',
531+
})
532+
533+
const html = await res.text()
534+
const $ = cheerio.load(html)
535+
expect($('#slug-page').text()).toBe('[slug] page')
536+
})
511537
})

0 commit comments

Comments
 (0)