From 9bf37bf9eaa4487474be6b07aea5b135268a84f6 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Wed, 2 Sep 2020 14:59:56 -0700 Subject: [PATCH 1/3] fix searchParams dev warning --- packages/next/next-server/lib/utils.ts | 1 + test/integration/dynamic-routing/pages/index.js | 9 +++++++++ test/integration/dynamic-routing/test/index.test.js | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/packages/next/next-server/lib/utils.ts b/packages/next/next-server/lib/utils.ts index 93b53fe693c1c..582fbf62dc035 100644 --- a/packages/next/next-server/lib/utils.ts +++ b/packages/next/next-server/lib/utils.ts @@ -363,6 +363,7 @@ export const urlObjectKeys = [ 'protocol', 'query', 'search', + 'searchParams', 'slashes', ] diff --git a/test/integration/dynamic-routing/pages/index.js b/test/integration/dynamic-routing/pages/index.js index bf9583e84609c..24b9ac0a69304 100644 --- a/test/integration/dynamic-routing/pages/index.js +++ b/test/integration/dynamic-routing/pages/index.js @@ -1,6 +1,15 @@ import Link from 'next/link' import { useRouter } from 'next/router' +if (typeof window !== 'undefined') { + window.caughtWarns = [] + const origWarn = window.console.warn + window.console.warn = function (...args) { + window.caughtWarns.push(args) + origWarn(...args) + } +} + const Page = () => { return (
diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js index a4ec4616e4c91..5537584a218d0 100644 --- a/test/integration/dynamic-routing/test/index.test.js +++ b/test/integration/dynamic-routing/test/index.test.js @@ -84,6 +84,12 @@ function runTests(dev) { expect(url).toBe('?fromHome=true') }) + it('should not have any console warnings', async () => { + const browser = await webdriver(appPort, '/') + const caughtWarns = await browser.eval(`window.caughtWarns`) + expect(caughtWarns).toEqual([]) + }) + it('should navigate to a dynamic page successfully', async () => { let browser try { From 8e9a613ec0bb29ecb3c6f4088df1aa7e712756b3 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Wed, 2 Sep 2020 15:59:05 -0700 Subject: [PATCH 2/3] add another test for route transition --- .../dynamic-routing/pages/d/[id].js | 9 +++++ .../dynamic-routing/pages/index.js | 3 ++ .../dynamic-routing/test/index.test.js | 37 ++++++++++++++++--- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 test/integration/dynamic-routing/pages/d/[id].js diff --git a/test/integration/dynamic-routing/pages/d/[id].js b/test/integration/dynamic-routing/pages/d/[id].js new file mode 100644 index 0000000000000..b17ed24dd8220 --- /dev/null +++ b/test/integration/dynamic-routing/pages/d/[id].js @@ -0,0 +1,9 @@ +import { useRouter } from 'next/router' + +const Page = () => { + const router = useRouter() + const { query } = router + return

This is {query.id}

+} + +export default Page diff --git a/test/integration/dynamic-routing/pages/index.js b/test/integration/dynamic-routing/pages/index.js index 24b9ac0a69304..c6bf5d0c59eb6 100644 --- a/test/integration/dynamic-routing/pages/index.js +++ b/test/integration/dynamic-routing/pages/index.js @@ -137,6 +137,9 @@ const Page = () => { Nested Catch-all route (multi)
+ + Dynamic route no as +

{JSON.stringify(Object.keys(useRouter().query))}

) diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js index 5537584a218d0..5427e53c2403b 100644 --- a/test/integration/dynamic-routing/test/index.test.js +++ b/test/integration/dynamic-routing/test/index.test.js @@ -84,11 +84,30 @@ function runTests(dev) { expect(url).toBe('?fromHome=true') }) - it('should not have any console warnings', async () => { - const browser = await webdriver(appPort, '/') - const caughtWarns = await browser.eval(`window.caughtWarns`) - expect(caughtWarns).toEqual([]) - }) + if (dev) { + it('should not have any console warnings on initial load', async () => { + const browser = await webdriver(appPort, '/') + expect(await browser.eval('window.caughtWarns')).toEqual([]) + }) + + it('should not have any console warnings when navigating to dynamic route', async () => { + let browser + try { + browser = await webdriver(appPort, '/') + await browser.eval('window.beforeNav = 1') + await browser.elementByCss('#dynamic-route-no-as').click() + await browser.waitForElementByCss('#asdf') + + expect(await browser.eval('window.beforeNav')).toBe(1) + + const text = await browser.elementByCss('#asdf').text() + expect(text).toMatch(/this is.*?dynamic-1/i) + expect(await browser.eval('window.caughtWarns')).toEqual([]) + } finally { + if (browser) await browser.close() + } + }) + } it('should navigate to a dynamic page successfully', async () => { let browser @@ -899,6 +918,14 @@ function runTests(dev) { helloworld: 'hello-world', }, }, + { + namedRegex: '^/d/(?[^/]+?)(?:/)?$', + page: '/d/[id]', + regex: normalizeRegEx('^\\/d\\/([^\\/]+?)(?:\\/)?$'), + routeKeys: { + id: 'id', + }, + }, { namedRegex: '^/dash/(?[^/]+?)(?:/)?$', page: '/dash/[hello-world]', From e93de426f39b617e9f6a2b0608952892cb6939b1 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Thu, 3 Sep 2020 10:58:04 -0700 Subject: [PATCH 3/3] remove searchParams change in favor of #16809 --- packages/next/next-server/lib/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/next-server/lib/utils.ts b/packages/next/next-server/lib/utils.ts index 582fbf62dc035..93b53fe693c1c 100644 --- a/packages/next/next-server/lib/utils.ts +++ b/packages/next/next-server/lib/utils.ts @@ -363,7 +363,6 @@ export const urlObjectKeys = [ 'protocol', 'query', 'search', - 'searchParams', 'slashes', ]