Unverified Commit 3417164c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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: https://github.com/vercel/next.js/issues/22750
parent 1f5c2c85
......@@ -51,7 +51,7 @@ export async function shouldLoadWithWebpack5(
export async function loadWebpackHook(phase: string, dir: string) {
let useWebpack5 = false
const worker: any = new Worker(__filename, { enableWorkerThreads: true })
const worker: any = new Worker(__filename, { enableWorkerThreads: false })
try {
useWebpack5 = Boolean(await worker.shouldLoadWithWebpack5(phase, dir))
} catch {
......
......@@ -340,7 +340,7 @@ export default class Server {
const { pathname, query } = parsedPath
let matchedPathname = pathname as string
const matchedPathnameNoExt = isDataUrl
let matchedPathnameNoExt = isDataUrl
? matchedPathname.replace(/\.json$/, '')
: matchedPathname
......@@ -355,6 +355,11 @@ export default class Server {
}
}
if (isDataUrl) {
matchedPathname = denormalizePagePath(matchedPathname)
matchedPathnameNoExt = denormalizePagePath(matchedPathnameNoExt)
}
const pageIsDynamic = isDynamicRoute(matchedPathnameNoExt)
const utils = getUtils({
pageIsDynamic,
......
export const getStaticProps = () => {
return {
props: {
hello: 'world',
},
}
}
export const getStaticPaths = () => {
return {
paths: [],
fallback: true,
}
}
export default function Page(props) {
return <p id="slug-page">[slug] page</p>
}
......@@ -508,4 +508,30 @@ describe('Required Server Files', () => {
expect(json.query).toEqual({ another: 'value' })
expect(json.url).toBe('/api/optional?another=value')
})
it('should match the index page correctly', async () => {
const res = await fetchViaHTTP(appPort, '/', undefined, {
headers: {
'x-matched-path': '/index',
},
redirect: 'manual',
})
const html = await res.text()
const $ = cheerio.load(html)
expect($('#index').text()).toBe('index page')
})
it('should match the root dyanmic page correctly', async () => {
const res = await fetchViaHTTP(appPort, '/index', undefined, {
headers: {
'x-matched-path': '/[slug]',
},
redirect: 'manual',
})
const html = await res.text()
const $ = cheerio.load(html)
expect($('#slug-page').text()).toBe('[slug] page')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment