Skip to content

Commit 3d948d0

Browse files
committed
add new test case for parallel routes
1 parent a8aca4c commit 3d948d0

File tree

43 files changed

+405
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+405
-52
lines changed

packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FlightRouterState } from '../../../../server/app-render/types'
22
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
3+
import { DEFAULT_SEGMENT_KEY } from '../../../../shared/lib/segment'
34
import { createRouterCacheKey } from '../create-router-cache-key'
45

56
export function findHeadInCache(
@@ -34,6 +35,11 @@ function findHeadInCacheImpl(
3435
// if we didn't find metadata in the page slot, check the other parallel routes
3536
for (const key of parallelRoutesKeys) {
3637
const [segment, childParallelRoutes] = parallelRoutes[key]
38+
// If the parallel is not matched and using the default segment,
39+
// skip searching the head from it.
40+
if (segment === DEFAULT_SEGMENT_KEY) {
41+
continue
42+
}
3743
const childSegmentMap = cache.parallelRoutes.get(key)
3844
if (!childSegmentMap) {
3945
continue
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Link from 'next/link'
2+
import { ReactNode } from 'react'
3+
4+
export default function Root({ children }: { children: ReactNode }) {
5+
return (
6+
<html>
7+
<body>
8+
<div>
9+
<Link href="/parallel-routes" id="to-parallel-routes">
10+
{`to /parallel-routes`}
11+
</Link>
12+
<br />
13+
<Link href="/parallel-routes-default" id="to-default">
14+
{`to /parallel-routes-default`}
15+
</Link>
16+
<br />
17+
18+
<Link href="/parallel-routes-no-children" id="to-no-children">
19+
{`to /parallel-routes-no-children`}
20+
</Link>
21+
<br />
22+
</div>
23+
{children}
24+
</body>
25+
</html>
26+
)
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default function Page() {
2+
return <p>index page</p>
3+
}
4+
5+
export async function generateMetadata() {
6+
await new Promise((resolve) => setTimeout(resolve, 1 * 1000))
7+
return {
8+
title: 'index page',
9+
}
10+
}
11+
12+
export const dynamic = 'force-dynamic'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'default @bar'
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Layout({ children }) {
2+
return (
3+
<div>
4+
<h2>@bar Layout</h2>
5+
<div id="bar-children">{children}</div>
6+
</div>
7+
)
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'page @bar'
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'test-page @bar'
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'default @foo'
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Layout({ children }) {
2+
return (
3+
<div>
4+
<h2>@foo Layout</h2>
5+
<div id="foo-children">{children}</div>
6+
</div>
7+
)
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'no-bar @foo'
3+
}

0 commit comments

Comments
 (0)