-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Handle defaultLocale on client router filter #47180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
i18n: { | ||
locales: ['en', 'nl'], | ||
defaultLocale: 'en', | ||
}, | ||
experimental: { | ||
clientRouterFilter: true, | ||
clientRouterFilterRedirects: true, | ||
}, | ||
redirects() { | ||
return [ | ||
{ | ||
source: '/to-new', | ||
destination: '/new', | ||
permanent: false, | ||
}, | ||
] | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<div> | ||
<Link href="/to-new" id="to-new"> | ||
To new (Default Locale) | ||
</Link> | ||
</div> | ||
<div> | ||
<Link href="/to-new" id="to-new-nl" locale="nl"> | ||
To new (NL) | ||
</Link> | ||
</div> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function New() { | ||
return <div id="new">New</div> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that this test passes with my changes but fails with the current
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failure Demo (current
|
||
}) | ||
|
||
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) | ||
}) | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ export class Playwright extends BrowserInterface { | |
if (!this.eventCallbacks[event]) { | ||
throw new Error( | ||
`Invalid event passed to browser.on, received ${event}. Valid events are ${Object.keys( | ||
event | ||
this.eventCallbacks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated but noticed this bug while debugging. |
||
)}` | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addLocale
skips adding the locale iflocale
is equal todefaultLocale
:next.js/packages/next/src/shared/lib/router/utils/add-locale.ts
Lines 15 to 23 in 02125cf