From 1afb7041be4d6d2b275be4c524dad69a05b49a5e Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 17 May 2021 16:33:17 -0500 Subject: [PATCH 1/3] Ensure default params are detected after rewrite --- .../loaders/next-serverless-loader/utils.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts b/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts index 2619b5a4f1142..b8f7fdb4f14ad 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader/utils.ts @@ -280,7 +280,7 @@ export function getUtils({ function normalizeDynamicRouteParams(params: ParsedUrlQuery) { let hasValidParams = true - if (!defaultRouteRegex) return { params, hasValidParams } + if (!defaultRouteRegex) return { params, hasValidParams: false } params = Object.keys(defaultRouteRegex.groups).reduce((prev, key) => { let value: string | string[] | undefined = params[key] @@ -288,15 +288,15 @@ export function getUtils({ // if the value matches the default value we can't rely // on the parsed params, this is used to signal if we need // to parse x-now-route-matches or not - const isDefaultValue = Array.isArray(value) - ? value.some((val) => { - const defaultValue = defaultRouteMatches![key] + const defaultValue = defaultRouteMatches![key] - return Array.isArray(defaultValue) - ? defaultValue.includes(val) - : defaultValue === val + const isDefaultValue = Array.isArray(defaultValue) + ? defaultValue.some((defaultVal) => { + return Array.isArray(value) + ? value.some((val) => val.includes(defaultVal)) + : value?.includes(defaultVal) }) - : value === defaultRouteMatches![key] + : value?.includes(defaultValue as string) if (isDefaultValue || typeof value === 'undefined') { hasValidParams = false From 71167e3045a52e123264081d6157f9fa5a3f362a Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 17 May 2021 18:13:30 -0500 Subject: [PATCH 2/3] Add test case --- .../required-server-files/test/index.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/integration/required-server-files/test/index.test.js b/test/integration/required-server-files/test/index.test.js index 72ba6a93fae0c..2c3d59d365019 100644 --- a/test/integration/required-server-files/test/index.test.js +++ b/test/integration/required-server-files/test/index.test.js @@ -216,6 +216,20 @@ describe('Required Server Files', () => { expect($2('#slug').text()).toBe('second') expect(isNaN(data2.random)).toBe(false) expect(data2.random).not.toBe(data.random) + + const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, { + headers: { + 'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json', + 'x-now-route-matches': '1=second&slug=second', + }, + }) + const $3 = cheerio.load(html3) + const data3 = JSON.parse($3('#props').text()) + + expect($3('#dynamic').text()).toBe('dynamic page') + expect($3('#slug').text()).toBe('second') + expect(isNaN(data3.random)).toBe(false) + expect(data3.random).not.toBe(data.random) }) it('should render fallback page correctly with x-matched-path and routes-matches', async () => { From eaff7bccd57b9816f248b68b0ee9f6df7ad199eb Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 18 May 2021 10:06:48 -0500 Subject: [PATCH 3/3] bump