mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1678838567947919) Follow-up to https://github.com/vercel/next.js/pull/46317. The issue is that, if: - `experimental.clientRouterFilter` is enabled - `i18n` is enabled with `defaultLocale` set - Next.js router navigates to a path that (1) is the same as `defaultLocale` and (2) will be redirected, then: - **Expected:** Should hard-navigate to this path without any locale prefix (and then redirect occurs) - **Actual:** Hard-navigates to this path with `defaultLocale` prefix, even though it's not needed (and then redirect occurrs) ### Solution This PR fixes the above issue by adding `defaultLocale` to `addLocale` which is passed to `handleHardNavigation`. [`addLocale` skips adding the locale if `locale` is equal to `defaultLocale`](https://github.com/vercel/next.js/blob/02125cf3b1dfba52b240fd6e0f959d896e4b6195/packages/next/src/shared/lib/router/utils/add-locale.ts#L17). ### Fixing a bug - [x] Related issues linked using `fixes #number` - [x] Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs Co-authored-by: JJ Kasper <[email protected]>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { join } from 'path'
|
|
import { createNextDescribe, FileRef } from 'e2e-utils'
|
|
|
|
createNextDescribe(
|
|
'i18-default-locale-redirect',
|
|
{
|
|
files: {
|
|
pages: new FileRef(join(__dirname, './app/pages')),
|
|
'next.config.js': new FileRef(join(__dirname, './app/next.config.js')),
|
|
},
|
|
},
|
|
({ next }) => {
|
|
it('should not request a path prefixed with default locale', async () => {
|
|
const browser = await next.browser('/')
|
|
let requestedDefaultLocalePath = false
|
|
browser.on('request', (request: any) => {
|
|
if (new URL(request.url(), 'http://n').pathname === '/en/to-new') {
|
|
requestedDefaultLocalePath = true
|
|
}
|
|
})
|
|
|
|
await browser.elementByCss('#to-new').click().waitForElementByCss('#new')
|
|
expect(await browser.elementByCss('#new').text()).toBe('New')
|
|
expect(requestedDefaultLocalePath).toBe(false)
|
|
})
|
|
|
|
it('should request a path prefixed with non-default locale', async () => {
|
|
const browser = await next.browser('/')
|
|
let requestedNonDefaultLocalePath = false
|
|
browser.on('request', (request: any) => {
|
|
if (new URL(request.url(), 'http://n').pathname === '/nl/to-new') {
|
|
requestedNonDefaultLocalePath = true
|
|
}
|
|
})
|
|
|
|
await browser
|
|
.elementByCss('#to-new-nl')
|
|
.click()
|
|
.waitForElementByCss('#new')
|
|
expect(await browser.elementByCss('#new').text()).toBe('New')
|
|
expect(requestedNonDefaultLocalePath).toBe(true)
|
|
})
|
|
}
|
|
)
|