From 27d78a5d41708fa25f8081ea30983d5234baed04 Mon Sep 17 00:00:00 2001 From: Rob Vermeer Date: Tue, 22 Jun 2021 18:55:52 +0200 Subject: [PATCH] Fix domain locales not available on client (#26083) * bug: Fix domain locales not available on client * Add test case * update tests Co-authored-by: JJ Kasper --- packages/next/client/router.ts | 1 + test/integration/build-output/test/index.test.js | 2 +- .../i18n-support-base-path/pages/index.js | 1 + test/integration/i18n-support/pages/index.js | 1 + test/integration/i18n-support/test/shared.js | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/next/client/router.ts b/packages/next/client/router.ts index 59236551956ec..ca4c5287f6bf4 100644 --- a/packages/next/client/router.ts +++ b/packages/next/client/router.ts @@ -43,6 +43,7 @@ const urlPropertyFields = [ 'isReady', 'isPreview', 'isLocaleDomain', + 'domainLocales', ] const routerEvents = [ 'routeChangeStart', diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index 233a760a02387..ef085280f3d45 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -129,7 +129,7 @@ describe('Build Output', () => { expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.17 : 8.51, 1) expect(err404Size.endsWith('kB')).toBe(true) - expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.9 : 204, 1) + expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.9 : 205, 1) expect(err404FirstLoad.endsWith('kB')).toBe(true) expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.7 : 196, 1) diff --git a/test/integration/i18n-support-base-path/pages/index.js b/test/integration/i18n-support-base-path/pages/index.js index 05a54778e482c..ec72e72258857 100644 --- a/test/integration/i18n-support-base-path/pages/index.js +++ b/test/integration/i18n-support-base-path/pages/index.js @@ -11,6 +11,7 @@ export default function Page(props) {

{router.locale}

{router.defaultLocale}

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.domainLocales)}

{JSON.stringify(router.query)}

{router.pathname}

{router.asPath}

diff --git a/test/integration/i18n-support/pages/index.js b/test/integration/i18n-support/pages/index.js index 05a54778e482c..ec72e72258857 100644 --- a/test/integration/i18n-support/pages/index.js +++ b/test/integration/i18n-support/pages/index.js @@ -11,6 +11,7 @@ export default function Page(props) {

{router.locale}

{router.defaultLocale}

{JSON.stringify(router.locales)}

+

{JSON.stringify(router.domainLocales)}

{JSON.stringify(router.query)}

{router.pathname}

{router.asPath}

diff --git a/test/integration/i18n-support/test/shared.js b/test/integration/i18n-support/test/shared.js index f0dac7dafbad3..98b0ec4f1a3f8 100644 --- a/test/integration/i18n-support/test/shared.js +++ b/test/integration/i18n-support/test/shared.js @@ -37,6 +37,21 @@ async function addDefaultLocaleCookie(browser) { } export function runTests(ctx) { + it.only('should have domainLocales available on useRouter', async () => { + const browser = await webdriver(ctx.appPort, `${ctx.basePath || '/'}`) + expect( + JSON.parse(await browser.elementByCss('#router-domain-locales').text()) + ).toEqual([ + { + http: true, + domain: 'example.do', + defaultLocale: 'do', + locales: ['do-BE'], + }, + { domain: 'example.com', defaultLocale: 'go', locales: ['go-BE'] }, + ]) + }) + it('should not error with similar named cookie to locale cookie', async () => { const res = await fetchViaHTTP( ctx.appPort,