From b97af95a26a3d2a2a93291594233eb30691070a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20Artmu=CC=88ller?= Date: Sun, 6 Dec 2020 16:11:13 +0100 Subject: [PATCH 1/2] Fix splitting page path by buildId --- packages/next/next-server/server/next-server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index d766f51a1c1df57..555b483564cfb9b 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1277,9 +1277,11 @@ export default class Server { const stripNextDataPath = (path: string) => { if (path.includes(this.buildId)) { - path = denormalizePagePath( - (path.split(this.buildId).pop() || '/').replace(/\.json$/, '') + const splitPath = path.substring( + path.indexOf(this.buildId) + this.buildId.length ) + + path = denormalizePagePath(splitPath.replace(/\.json$/, '')) } if (this.nextConfig.i18n) { From 74c18d9fa0802165a06b0f32560e12012991f18c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 19 Jan 2021 12:08:07 -0600 Subject: [PATCH 2/2] Add test for i18n + developments page --- .../pages/developments/index.js | 33 +++++++++++++++++++ .../i18n-support/pages/developments/index.js | 33 +++++++++++++++++++ test/integration/i18n-support/test/shared.js | 30 +++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 test/integration/i18n-support-base-path/pages/developments/index.js create mode 100644 test/integration/i18n-support/pages/developments/index.js diff --git a/test/integration/i18n-support-base-path/pages/developments/index.js b/test/integration/i18n-support-base-path/pages/developments/index.js new file mode 100644 index 000000000000000..cbd5858aec7ee55 --- /dev/null +++ b/test/integration/i18n-support-base-path/pages/developments/index.js @@ -0,0 +1,33 @@ +import Link from 'next/link' +import { useRouter } from 'next/router' + +export default function Page(props) { + const router = useRouter() + + return ( + <> +

developments page

+

{JSON.stringify(props)}

+

{router.locale}

+

{router.defaultLocale}

+

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.query)}

+

{router.pathname}

+

{router.asPath}

+ + to / + +
+ + ) +} + +export const getServerSideProps = ({ locale, locales, defaultLocale }) => { + return { + props: { + locale, + locales, + defaultLocale, + }, + } +} diff --git a/test/integration/i18n-support/pages/developments/index.js b/test/integration/i18n-support/pages/developments/index.js new file mode 100644 index 000000000000000..cbd5858aec7ee55 --- /dev/null +++ b/test/integration/i18n-support/pages/developments/index.js @@ -0,0 +1,33 @@ +import Link from 'next/link' +import { useRouter } from 'next/router' + +export default function Page(props) { + const router = useRouter() + + return ( + <> +

developments page

+

{JSON.stringify(props)}

+

{router.locale}

+

{router.defaultLocale}

+

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.query)}

+

{router.pathname}

+

{router.asPath}

+ + to / + +
+ + ) +} + +export const getServerSideProps = ({ locale, locales, defaultLocale }) => { + return { + props: { + locale, + locales, + defaultLocale, + }, + } +} diff --git a/test/integration/i18n-support/test/shared.js b/test/integration/i18n-support/test/shared.js index fcb6dba018737ea..47ff03d8677635b 100644 --- a/test/integration/i18n-support/test/shared.js +++ b/test/integration/i18n-support/test/shared.js @@ -37,6 +37,36 @@ async function addDefaultLocaleCookie(browser) { } export function runTests(ctx) { + it('should navigate to page with same name as development buildId', async () => { + const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`) + + await browser.eval(`(function() { + window.beforeNav = 1 + window.next.router.push('/developments') + })()`) + + await browser.waitForElementByCss('#developments') + expect(await browser.eval('window.beforeNav')).toBe(1) + expect(await browser.elementByCss('#router-locale').text()).toBe('en-US') + expect(await browser.elementByCss('#router-default-locale').text()).toBe( + 'en-US' + ) + expect(await browser.elementByCss('#router-pathname').text()).toBe( + '/developments' + ) + expect(await browser.elementByCss('#router-as-path').text()).toBe( + '/developments' + ) + expect( + JSON.parse(await browser.elementByCss('#router-query').text()) + ).toEqual({}) + expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({ + locales, + locale: 'en-US', + defaultLocale: 'en-US', + }) + }) + it('should redirect to locale domain correctly client-side', async () => { const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`)