Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't skip the cookie if no locale is detected in the route #1235

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

strebl
Copy link

@strebl strebl commented Jul 18, 2021

That PR fixes #1234.

It uses the cookie locale, if no locale is set yet.

@strebl strebl mentioned this pull request Jul 19, 2021
3 tasks
@rchl
Copy link
Collaborator

rchl commented Jul 19, 2021

One thing I would also need is a test that reproduces the issue fixed here. Should probably be added in test/browser.test.js.

@rchl
Copy link
Collaborator

rchl commented Jul 20, 2021

I can't push to your branch since you haven't checked the relevant checkbox but here is the test:

describe(`${browserString} (onlyOnNoPrefix + prefix)`, () => {
  /** @type {Nuxt} */
  let nuxt
  /** @type {import('playwright-chromium').ChromiumBrowser} */
  let browser

  beforeAll(async () => {
    const overrides = {
      i18n: {
        defaultLocale: 'en',
        strategy: 'prefix',
        detectBrowserLanguage: {
          onlyOnNoPrefix: true
        }
      }
    }

    nuxt = (await setup(loadConfig(__dirname, 'basic', overrides, { merge: true }))).nuxt
    browser = await createBrowser()
  })

  afterAll(async () => {
    if (browser) {
      await browser.close()
    }
    await nuxt.close()
  })

  test('uses saved locale cookie when redirecting from root', async () => {
    const page = await browser.newPage({ locale: 'fr' })
    // Ensure the detected locale cookie is saved
    await page.goto(url('/fr'))
    expect(await (await page.$('body'))?.textContent()).toContain('locale: fr')
    expect(await getRouteFullPath(page)).toBe('/fr')
    // Verify that we navigate to saved locale
    await page.goto(url('/'))
    expect(await (await page.$('body'))?.textContent()).toContain('locale: fr')
    expect(await getRouteFullPath(page)).toBe('/fr')
  })
})

@strebl
Copy link
Author

strebl commented Jul 21, 2021

Thank you very much @rchl

I don't see the checkbox mentioned in the github docs.

However I've added your test 👍🏻 All tests are green 🎉 I see some multiple errors tho: Error generating route "/about-us": This page could not be found.

@rchl rchl merged commit 6c9b48f into nuxt-modules:master Jul 21, 2021
@rchl
Copy link
Collaborator

rchl commented Jul 21, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i18n cookie gets ignored
2 participants