From 1224c390157cb86db38d77047c7acdfd3c5912e9 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 17 Jan 2020 10:30:08 -0600 Subject: [PATCH 1/2] Fix SSG data request failing with trailing slash --- packages/next/next-server/lib/router/router.ts | 5 +++++ test/integration/prerender/pages/index.js | 2 +- test/integration/prerender/test/index.test.js | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 508b941e191bbad..a10aa93906c3796 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -668,6 +668,11 @@ export default class Router implements BaseRouter { let pathname = parse(asPath).pathname pathname = !pathname || pathname === '/' ? '/index' : pathname + // remove trailing slash from path + if (pathname.substr(pathname.length - 1) === '/') { + pathname = pathname.substr(0, pathname.length - 1) + } + return process.env.NODE_ENV === 'production' && (_cachedData = this.sdc[pathname]) ? Promise.resolve(_cachedData) diff --git a/test/integration/prerender/pages/index.js b/test/integration/prerender/pages/index.js index 295502017aeb649..a81149f600a59f5 100644 --- a/test/integration/prerender/pages/index.js +++ b/test/integration/prerender/pages/index.js @@ -14,7 +14,7 @@ const Page = ({ world, time }) => { <>

hello {world}

time: {time} - + to another
diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index e71be48a58827fe..2b8f4109518075a 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -134,9 +134,11 @@ const navigateTest = (dev = false) => { // go to /another async function goFromHomeToAnother() { + await browser.eval('window.beforeAnother = true') await browser.elementByCss('#another').click() await browser.waitForElementByCss('#home') text = await browser.elementByCss('p').text() + expect(await browser.eval('window.beforeAnother')).toBe(true) expect(text).toMatch(/hello.*?world/) } await goFromHomeToAnother() From cab730c4ee27b2100b30e8d28de56d1ec83b47ce Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 17 Jan 2020 10:39:45 -0600 Subject: [PATCH 2/2] Update to re-use toRoute method --- packages/next/next-server/lib/router/router.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index a10aa93906c3796..0abdad552fbde27 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -666,12 +666,7 @@ export default class Router implements BaseRouter { _getStaticData = (asPath: string, _cachedData?: object): Promise => { let pathname = parse(asPath).pathname - pathname = !pathname || pathname === '/' ? '/index' : pathname - - // remove trailing slash from path - if (pathname.substr(pathname.length - 1) === '/') { - pathname = pathname.substr(0, pathname.length - 1) - } + pathname = toRoute(!pathname || pathname === '/' ? '/index' : pathname) return process.env.NODE_ENV === 'production' && (_cachedData = this.sdc[pathname])