From 34262cb4992bdba23979fbfc0495c8e4f754d5dd Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 4 Mar 2021 15:22:02 -0600 Subject: [PATCH 1/2] Fix index revalidate with dynamic route --- .../next/next-server/server/next-server.ts | 7 ++++- .../required-server-files/pages/[slug].js | 18 +++++++++++++ .../required-server-files/test/index.test.js | 26 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/integration/required-server-files/pages/[slug].js diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index c7ccd7113208d..3f928b43a73fb 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -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, diff --git a/test/integration/required-server-files/pages/[slug].js b/test/integration/required-server-files/pages/[slug].js new file mode 100644 index 0000000000000..9898cbe9722d9 --- /dev/null +++ b/test/integration/required-server-files/pages/[slug].js @@ -0,0 +1,18 @@ +export const getStaticProps = () => { + return { + props: { + hello: 'world', + }, + } +} + +export const getStaticPaths = () => { + return { + paths: [], + fallback: true, + } +} + +export default function Page(props) { + return

[slug] page

+} diff --git a/test/integration/required-server-files/test/index.test.js b/test/integration/required-server-files/test/index.test.js index 57b4260e30af9..cf02ed9d409d1 100644 --- a/test/integration/required-server-files/test/index.test.js +++ b/test/integration/required-server-files/test/index.test.js @@ -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') + }) }) From 1fcbf2e1ccf4519560a297a39a549965f82f113b Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 4 Mar 2021 15:22:34 -0600 Subject: [PATCH 2/2] disable worker threads for config check --- packages/next/next-server/server/config-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/next-server/server/config-utils.ts b/packages/next/next-server/server/config-utils.ts index 7193ed1ef8a40..5536da606641e 100644 --- a/packages/next/next-server/server/config-utils.ts +++ b/packages/next/next-server/server/config-utils.ts @@ -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 {