-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix interpolation of dynamic params in intercepting route pathnames
In a pathname for an intercepting route, a dynamic path param might occur multiple types, e.g. `'/[locale]/example/(...)[locale]/intercepted'`. We need to make sure that each occurence is replaced with the actual value during interpolation. The handling of such pathnames is already done correctly in the Node.js runtime, but not in the Edge runtime. fixes #70654
- Loading branch information
1 parent
eecf90c
commit 4f9a3f4
Showing
11 changed files
with
130 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...and-interception-from-root/app/[locale]/example/@modal/(...)[locale]/intercepted/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<h2>Page intercepted from root</h2> | ||
<Link href="/en/example">Back to /en/example</Link> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
...pp-dir/parallel-routes-and-interception-from-root/app/[locale]/example/@modal/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
3 changes: 3 additions & 0 deletions
3
...e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/example/@modal/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return null | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/example/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/example/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ReactNode } from 'react' | ||
|
||
export default function Layout({ | ||
children, | ||
modal, | ||
}: { | ||
children: ReactNode | ||
modal: ReactNode | ||
}) { | ||
return ( | ||
<div> | ||
{children} | ||
{modal} | ||
</div> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/example/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<h1>Example Page</h1> | ||
<Link href="/en/intercepted">Intercept /en/intercepted</Link> | ||
</div> | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
test/e2e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export const runtime = 'edge' | ||
|
||
export default async function RootLayout({ | ||
children, | ||
params, | ||
}: { | ||
children: React.ReactNode | ||
params: Promise<{ locale: string }> | ||
}) { | ||
const locale = (await params).locale | ||
console.log('RootLayout rendered, locale:', locale) | ||
|
||
return ( | ||
<html lang={locale}> | ||
<body> | ||
<p>Locale: {locale}</p> | ||
{children} | ||
</body> | ||
</html> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-routes-and-interception-from-root/app/[locale]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Link href="/en/example">Go to /en/example</Link> | ||
</div> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
test/e2e/app-dir/parallel-routes-and-interception-from-root/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
39 changes: 39 additions & 0 deletions
39
...llel-routes-and-interception-from-root/parallel-routes-and-interception-from-root.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('parallel-routes-and-interception-from-root', () => { | ||
const { next, isNextDeploy } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should interpolate [locale] in "/[locale]/example/(...)[locale]/intercepted"', async () => { | ||
const browser = await next.browser('/en/example') | ||
|
||
expect(await browser.elementByCss('h1').text()).toBe('Example Page') | ||
expect(await browser.elementByCss('p').text()).toBe('Locale: en') | ||
|
||
if (!isNextDeploy) { | ||
expect(next.cliOutput).toInclude('RootLayout rendered, locale: en') | ||
} | ||
|
||
const cliOutputLength = next.cliOutput.length | ||
|
||
await browser.elementByCss('a').click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('h2').text()).toBe( | ||
'Page intercepted from root' | ||
) | ||
}) | ||
|
||
// Ensure that the locale is still correctly rendered in the root layout. | ||
expect(await browser.elementByCss('p').text()).toBe('Locale: en') | ||
|
||
// ...and that the root layout was not rerendered. | ||
if (!isNextDeploy) { | ||
expect(next.cliOutput.slice(cliOutputLength)).not.toInclude( | ||
'RootLayout rendered, locale: en' | ||
) | ||
} | ||
}) | ||
}) |