From 4be2b2d1cccf83da2e15fc4454eacc5cbd99a612 Mon Sep 17 00:00:00 2001 From: Richard van der Dys Date: Sun, 16 Feb 2020 14:25:53 +0200 Subject: [PATCH 1/3] Fixed pathname check in router Remove the query portion of the URL when checking paths --- packages/next/next-server/lib/router/router.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 6bd26cddd8c1..8d45033db7f3 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -235,7 +235,8 @@ export default class Router implements BaseRouter { if ( e.state && this.isSsr && - e.state.url === this.pathname && + // Remove the query portion of the URL when checking paths + e.state.url.replace(/\?(.)+/, '') === this.pathname && e.state.as === this.asPath ) { return From e104aefa20e077f6360f52223dff4c580873059f Mon Sep 17 00:00:00 2001 From: Richard van der Dys Date: Wed, 19 Feb 2020 10:44:01 +0200 Subject: [PATCH 2/3] Updated change and added trial test --- packages/next/next-server/lib/router/router.ts | 5 ++--- test/integration/production/test/index.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 8d45033db7f3..9cae5079d51d 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -235,9 +235,8 @@ export default class Router implements BaseRouter { if ( e.state && this.isSsr && - // Remove the query portion of the URL when checking paths - e.state.url.replace(/\?(.)+/, '') === this.pathname && - e.state.as === this.asPath + e.state.as === this.asPath && + parse(e.state.url).pathname === this.pathname ) { return } diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index a0f198f583e9..fceeb17c60d2 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -310,6 +310,21 @@ describe('Production Usage', () => { expect(newText).toBe('server') }) + it('should navigate back then forward', async () => { + const browser = await webdriver(appPort, '/external-and-back') + const initialText = await browser.elementByCss('p').text() + expect(initialText).toBe('server') + + await browser + .elementByCss('a') + .click() + .waitForElementByCss('input') + .back() + .waitForElementByCss('p') + .forward() + .waitForElementByCss('input') + }) + it('should change query correctly', async () => { const browser = await webdriver(appPort, '/query?id=0') let id = await browser.elementByCss('#q0').text() From 5065037e0f3277190185cc739a5a1d13d096ee1c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 19 Feb 2020 10:14:05 -0600 Subject: [PATCH 3/3] Update test --- test/integration/production/test/index.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 27ba872cbe7f..714d16dcde80 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -310,8 +310,8 @@ describe('Production Usage', () => { expect(newText).toBe('server') }) - it('should navigate back then forward', async () => { - const browser = await webdriver(appPort, '/external-and-back') + it('should navigate to external site and back (with query)', async () => { + const browser = await webdriver(appPort, '/external-and-back?hello=world') const initialText = await browser.elementByCss('p').text() expect(initialText).toBe('server') @@ -321,8 +321,10 @@ describe('Production Usage', () => { .waitForElementByCss('input') .back() .waitForElementByCss('p') - .forward() - .waitForElementByCss('input') + + await waitFor(1000) + const newText = await browser.elementByCss('p').text() + expect(newText).toBe('server') }) it('should change query correctly', async () => {