Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
13b8d58a
Unverified
Commit
13b8d58a
authored
Jun 04, 2025
by
Jiachi Liu
Committed by
GitHub
Jun 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] only render one metadata outlet (#80146)
parent
895908a3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
16 deletions
+15
-16
metadata.tsx
packages/next/src/lib/metadata/metadata.tsx
+7
-6
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+4
-5
walk-tree-with-flight-router-state.tsx
.../server/app-render/walk-tree-with-flight-router-state.tsx
+1
-1
metadata-streaming-parallel-routes.test.ts
...arallel-routes/metadata-streaming-parallel-routes.test.ts
+3
-4
No files found.
packages/next/src/lib/metadata/metadata.tsx
View file @
13b8d58a
...
@@ -78,7 +78,7 @@ export function createMetadataComponents({
...
@@ -78,7 +78,7 @@ export function createMetadataComponents({
ViewportTree
:
React
.
ComponentType
ViewportTree
:
React
.
ComponentType
getMetadataReady
:
()
=>
Promise
<
void
>
getMetadataReady
:
()
=>
Promise
<
void
>
getViewportReady
:
()
=>
Promise
<
void
>
getViewportReady
:
()
=>
Promise
<
void
>
StreamingMetadataOutlet
:
React
.
ComponentType
StreamingMetadataOutlet
:
React
.
ComponentType
|
null
}
{
}
{
const
searchParams
=
createServerSearchParamsForMetadata
(
const
searchParams
=
createServerSearchParamsForMetadata
(
parsedQuery
,
parsedQuery
,
...
@@ -243,13 +243,14 @@ export function createMetadataComponents({
...
@@ -243,13 +243,14 @@ export function createMetadataComponents({
return
undefined
return
undefined
}
}
function
StreamingMetadataOutlet
()
{
function
StreamingMetadataOutletImpl
()
{
if
(
serveStreamingMetadata
)
{
return
<
AsyncMetadataOutlet
promise=
{
resolveFinalMetadata
()
}
/>
return
<
AsyncMetadataOutlet
promise=
{
resolveFinalMetadata
()
}
/>
}
return
null
}
}
const
StreamingMetadataOutlet
=
serveStreamingMetadata
?
StreamingMetadataOutletImpl
:
null
return
{
return
{
ViewportTree
,
ViewportTree
,
MetadataTree
,
MetadataTree
,
...
...
packages/next/src/server/app-render/create-component-tree.tsx
View file @
13b8d58a
...
@@ -42,7 +42,7 @@ export function createComponentTree(props: {
...
@@ -42,7 +42,7 @@ export function createComponentTree(props: {
missingSlots
?:
Set
<
string
>
missingSlots
?:
Set
<
string
>
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
authInterrupts
:
boolean
authInterrupts
:
boolean
StreamingMetadataOutlet
:
React
.
ComponentType
StreamingMetadataOutlet
:
React
.
ComponentType
|
null
}):
Promise
<
CacheNodeSeedData
>
{
}):
Promise
<
CacheNodeSeedData
>
{
return
getTracer
().
trace
(
return
getTracer
().
trace
(
NextNodeServerSpan
.
createComponentTree
,
NextNodeServerSpan
.
createComponentTree
,
...
@@ -395,7 +395,9 @@ async function createComponentTreeInternal({
...
@@ -395,7 +395,9 @@ async function createComponentTreeInternal({
// Use the same condition to render metadataOutlet as metadata
// Use the same condition to render metadataOutlet as metadata
const
metadataOutlet
=
StreamingMetadataOutlet
?
(
const
metadataOutlet
=
StreamingMetadataOutlet
?
(
<
StreamingMetadataOutlet
/>
<
StreamingMetadataOutlet
/>
)
:
undefined
)
:
(
<
MetadataOutlet
ready=
{
getMetadataReady
}
/>
)
const
notFoundElement
=
NotFound
?
(
const
notFoundElement
=
NotFound
?
(
<>
<>
...
@@ -716,9 +718,6 @@ async function createComponentTreeInternal({
...
@@ -716,9 +718,6 @@ async function createComponentTreeInternal({
{
layerAssets
}
{
layerAssets
}
<
OutletBoundary
>
<
OutletBoundary
>
<
MetadataOutlet
ready=
{
getViewportReady
}
/>
<
MetadataOutlet
ready=
{
getViewportReady
}
/>
{
/* Blocking metadata outlet */
}
<
MetadataOutlet
ready=
{
getMetadataReady
}
/>
{
/* Streaming metadata outlet */
}
{
metadataOutlet
}
{
metadataOutlet
}
</
OutletBoundary
>
</
OutletBoundary
>
</
React
.
Fragment
>,
</
React
.
Fragment
>,
...
...
packages/next/src/server/app-render/walk-tree-with-flight-router-state.tsx
View file @
13b8d58a
...
@@ -56,7 +56,7 @@ export async function walkTreeWithFlightRouterState({
...
@@ -56,7 +56,7 @@ export async function walkTreeWithFlightRouterState({
getViewportReady
:
()
=>
Promise
<
void
>
getViewportReady
:
()
=>
Promise
<
void
>
ctx
:
AppRenderContext
ctx
:
AppRenderContext
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
StreamingMetadataOutlet
:
React
.
ComponentType
StreamingMetadataOutlet
:
React
.
ComponentType
|
null
}):
Promise
<
FlightDataPath
[]
>
{
}):
Promise
<
FlightDataPath
[]
>
{
const
{
const
{
renderOpts
:
{
nextFontManifest
,
experimental
},
renderOpts
:
{
nextFontManifest
,
experimental
},
...
...
test/e2e/app-dir/metadata-streaming-parallel-routes/metadata-streaming-parallel-routes.test.ts
View file @
13b8d58a
...
@@ -9,13 +9,12 @@ describe('app-dir - metadata-streaming', () => {
...
@@ -9,13 +9,12 @@ describe('app-dir - metadata-streaming', () => {
it
(
'should only insert metadata once for parallel routes when slots match'
,
async
()
=>
{
it
(
'should only insert metadata once for parallel routes when slots match'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/parallel-routes'
)
const
browser
=
await
next
.
browser
(
'/parallel-routes'
)
expect
((
await
browser
.
elementsByCss
(
'head title'
)).
length
).
toBe
(
1
)
expect
((
await
browser
.
elementsByCss
(
'title'
)).
length
).
toBe
(
1
)
expect
((
await
browser
.
elementsByCss
(
'body title'
)).
length
).
toBe
(
0
)
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'parallel title'
)
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'parallel title'
)
const
$
=
await
next
.
render$
(
'/parallel-routes'
)
const
$
=
await
next
.
render$
(
'/parallel-routes'
)
expect
(
$
(
'title'
).
length
).
toBe
(
1
)
expect
(
$
(
'title'
).
length
).
toBe
(
1
)
// We can't ensure if it's inserted into
head or body since it's a race condition,
// We can't ensure if it's inserted into head or body since it's a race condition,
// where sometimes the metadata can be suspended.
// where sometimes the metadata can be suspended.
expect
(
$
(
'title'
).
text
()).
toBe
(
'parallel title'
)
expect
(
$
(
'title'
).
text
()).
toBe
(
'parallel title'
)
...
@@ -51,7 +50,7 @@ describe('app-dir - metadata-streaming', () => {
...
@@ -51,7 +50,7 @@ describe('app-dir - metadata-streaming', () => {
const
browser
=
await
next
.
browser
(
'/parallel-routes-default'
)
const
browser
=
await
next
.
browser
(
'/parallel-routes-default'
)
expect
((
await
browser
.
elementsByCss
(
'title'
)).
length
).
toBe
(
1
)
expect
((
await
browser
.
elementsByCss
(
'title'
)).
length
).
toBe
(
1
)
expect
(
await
browser
.
elementByCss
(
'
body
title'
).
text
()).
toBe
(
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'parallel-routes-default layout title'
'parallel-routes-default layout title'
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment