Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index revalidate with dynamic route in minimal mode #22783

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})