Skip to content

Commit

Permalink
Merge branch 'canary' into bump/babel-cache-key
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Apr 22, 2021
2 parents 37d24a7 + 9edb1ef commit c75f31b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export function addLocale(
defaultLocale?: string
) {
if (process.env.__NEXT_I18N_SUPPORT) {
const pathLower = path.toLowerCase()
const pathname = pathNoQueryHash(path)
const pathLower = pathname.toLowerCase()
const localeLower = locale && locale.toLowerCase()

return locale &&
Expand Down
2 changes: 2 additions & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"dynamic.d.ts",
"error.js",
"error.d.ts",
"experimental-script.js",
"experimental-script.d.ts",
"head.js",
"head.d.ts",
"image.js",
Expand Down
78 changes: 78 additions & 0 deletions test/integration/i18n-support/test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,84 @@ export function runTests(ctx) {
expect(await res.text()).toContain('index page')
})

it('should not add duplicate locale key when navigating back to root path with query params', async () => {
const basePath = ctx.basePath || ''
const queryKey = 'query'
const queryValue = '1'
const browser = await webdriver(
ctx.appPort,
`${basePath}/fr?${queryKey}=${queryValue}`
)

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr`
)
expect(await browser.elementByCss('#router-pathname').text()).toBe('/')
expect(
JSON.parse(await browser.elementByCss('#router-query').text())
).toEqual({ [queryKey]: queryValue })
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')

await browser
.elementByCss('#to-another')
.click()
.waitForElementByCss('#another')

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr/another`
)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/another'
)
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')

await browser.back().waitForElementByCss('#index')

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr`
)
expect(await browser.elementByCss('#router-pathname').text()).toBe('/')
expect(
JSON.parse(await browser.elementByCss('#router-query').text())
).toEqual({ [queryKey]: queryValue })
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')
})

it('should not add duplicate locale key when navigating back to root path with hash', async () => {
const basePath = ctx.basePath || ''
const hashValue = '#anchor-1'
const browser = await webdriver(ctx.appPort, `${basePath}/fr${hashValue}`)

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr`
)
expect(await browser.eval(() => document.location.hash)).toBe(hashValue)
expect(await browser.elementByCss('#router-pathname').text()).toBe('/')
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')

await browser
.elementByCss('#to-another')
.click()
.waitForElementByCss('#another')

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr/another`
)
expect(await browser.elementByCss('#router-pathname').text()).toBe(
'/another'
)
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')

await browser.back().waitForElementByCss('#index')

expect(await browser.eval(() => document.location.pathname)).toBe(
`${basePath}/fr`
)
expect(await browser.eval(() => document.location.hash)).toBe(hashValue)
expect(await browser.elementByCss('#router-pathname').text()).toBe('/')
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')
})

it('should handle navigating back to different casing of locale', async () => {
const browser = await webdriver(
ctx.appPort,
Expand Down

0 comments on commit c75f31b

Please sign in to comment.