Skip to content

Commit 61b81f4

Browse files
authored
[metadata] fix duplicate metadata for parallel routes (#76669)
1 parent 6fa1be8 commit 61b81f4

File tree

10 files changed

+56
-1
lines changed

10 files changed

+56
-1
lines changed

packages/next/src/server/app-render/create-component-tree.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ async function createComponentTreeInternal({
527527
missingSlots,
528528
preloadCallbacks,
529529
authInterrupts,
530-
StreamingMetadata,
530+
StreamingMetadata: isChildrenRouteKey ? StreamingMetadata : null,
531531
// `StreamingMetadataOutlet` is used to conditionally throw. In the case of parallel routes we will have more than one page
532532
// but we only want to throw on the first one.
533533
StreamingMetadataOutlet: isChildrenRouteKey
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'default @bar'
3+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'page @bar'
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'default @foo'
3+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return 'page @foo'
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function Layout({ children, bar, foo }) {
2+
return (
3+
<div>
4+
<h1>Parallel Routes Layout</h1>
5+
<div id="nested-children">{children}</div>
6+
<div id="foo-slot">{foo}</div>
7+
<div id="bar-slot">{bar}</div>
8+
</div>
9+
)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return <div>Hello from Nested</div>
3+
}
4+
5+
export const metadata = {
6+
title: 'parallel title',
7+
}

test/e2e/app-dir/metadata-streaming/metadata-streaming.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ describe('app-dir - metadata-streaming', () => {
8888
expect((await browser.elementsByCss('body meta')).length).toBe(9)
8989
})
9090

91+
it('should only insert metadata once for parallel routes', async () => {
92+
const browser = await next.browser('/parallel-routes')
93+
94+
expect((await browser.elementsByCss('head title')).length).toBe(1)
95+
expect((await browser.elementsByCss('body title')).length).toBe(0)
96+
97+
const $ = await next.render$('/parallel-routes')
98+
expect($('title').length).toBe(1)
99+
})
100+
91101
describe('dynamic api', () => {
92102
it('should render metadata to body', async () => {
93103
const $ = await next.render$('/dynamic-api')

0 commit comments

Comments
 (0)