Skip to content

Commit

Permalink
Fix index revalidate with dynamic route in minimal mode (#22783)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ijjk committed Mar 4, 2021
1 parent 1f5c2c8 commit 3417164
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/next-server/server/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -355,6 +355,11 @@ export default class Server {
}
}

if (isDataUrl) {
matchedPathname = denormalizePagePath(matchedPathname)
matchedPathnameNoExt = denormalizePagePath(matchedPathnameNoExt)
}

const pageIsDynamic = isDynamicRoute(matchedPathnameNoExt)
const utils = getUtils({
pageIsDynamic,
Expand Down
18 changes: 18 additions & 0 deletions test/integration/required-server-files/pages/[slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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>
}
26 changes: 26 additions & 0 deletions test/integration/required-server-files/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 3417164

Please sign in to comment.