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
0b136b27
Unverified
Commit
0b136b27
authored
Feb 20, 2025
by
Jiachi Liu
Committed by
GitHub
Feb 20, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] fix streaming metadata triggering error boundaries (#76280)
parent
de535e48
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
9 deletions
+58
-9
error-boundary.tsx
...client/components/http-access-fallback/error-boundary.tsx
+1
-1
async-metadata.tsx
packages/next/src/lib/metadata/async-metadata.tsx
+4
-1
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+17
-5
not-found.tsx
...ir/metadata-streaming/app/notfound/boundary/not-found.tsx
+7
-0
page.tsx
...app-dir/metadata-streaming/app/notfound/boundary/page.tsx
+14
-0
page.tsx
test/e2e/app-dir/metadata-streaming/app/notfound/page.tsx
+2
-2
metadata-streaming.test.ts
...e2e/app-dir/metadata-streaming/metadata-streaming.test.ts
+13
-0
No files found.
packages/next/src/client/components/http-access-fallback/error-boundary.tsx
View file @
0b136b27
...
@@ -136,7 +136,7 @@ class HTTPAccessFallbackErrorBoundary extends React.Component<
...
@@ -136,7 +136,7 @@ class HTTPAccessFallbackErrorBoundary extends React.Component<
<
meta
name=
"robots"
content=
"noindex"
/>
<
meta
name=
"robots"
content=
"noindex"
/>
{
process
.
env
.
NODE_ENV
===
'development'
&&
(
{
process
.
env
.
NODE_ENV
===
'development'
&&
(
<
meta
<
meta
name=
"next-error"
name=
"
boundary-
next-error"
content=
{
getAccessFallbackErrorTypeByStatus
(
triggeredStatus
)
}
content=
{
getAccessFallbackErrorTypeByStatus
(
triggeredStatus
)
}
/>
/>
)
}
)
}
...
...
packages/next/src/lib/metadata/async-metadata.tsx
View file @
0b136b27
...
@@ -27,7 +27,10 @@ function BrowserResolvedMetadata({
...
@@ -27,7 +27,10 @@ function BrowserResolvedMetadata({
}:
{
}:
{
promise
:
Promise
<
StreamingMetadataResolvedState
>
promise
:
Promise
<
StreamingMetadataResolvedState
>
})
{
})
{
const
{
metadata
}
=
use
(
promise
)
const
{
metadata
,
error
}
=
use
(
promise
)
// If there's metadata error on client, discard the browser metadata
// and let metadata outlet deal with the error. This will avoid the duplication metadata.
if
(
error
)
return
null
return
metadata
return
metadata
}
}
...
...
packages/next/src/server/app-render/create-component-tree.tsx
View file @
0b136b27
...
@@ -93,7 +93,7 @@ async function createComponentTreeInternal({
...
@@ -93,7 +93,7 @@ async function createComponentTreeInternal({
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
authInterrupts
:
boolean
authInterrupts
:
boolean
StreamingMetadata
:
React
.
ComponentType
<
{}
>
|
null
StreamingMetadata
:
React
.
ComponentType
<
{}
>
|
null
StreamingMetadataOutlet
:
React
.
ComponentType
StreamingMetadataOutlet
:
React
.
ComponentType
|
null
}):
Promise
<
CacheNodeSeedData
>
{
}):
Promise
<
CacheNodeSeedData
>
{
const
{
const
{
renderOpts
:
{
nextConfigOutput
,
experimental
},
renderOpts
:
{
nextConfigOutput
,
experimental
},
...
@@ -397,9 +397,15 @@ async function createComponentTreeInternal({
...
@@ -397,9 +397,15 @@ async function createComponentTreeInternal({
// Only render metadata on the actual SSR'd segment not the `default` segment,
// Only render metadata on the actual SSR'd segment not the `default` segment,
// as it's used as a placeholder for navigation.
// as it's used as a placeholder for navigation.
const
isNotDefaultSegment
=
actualSegment
!==
DEFAULT_SEGMENT_KEY
const
metadata
=
const
metadata
=
actualSegment
!==
DEFAULT_SEGMENT_KEY
&&
StreamingMetadata
?
(
isNotDefaultSegment
&&
StreamingMetadata
?
<
StreamingMetadata
/>
:
undefined
<
StreamingMetadata
/>
// Use the same condition to render metadataOutlet as metadata
const
metadataOutlet
=
isNotDefaultSegment
&&
StreamingMetadataOutlet
?
(
<
StreamingMetadataOutlet
/>
)
:
undefined
)
:
undefined
const
notFoundElement
=
NotFound
?
(
const
notFoundElement
=
NotFound
?
(
...
@@ -522,7 +528,11 @@ async function createComponentTreeInternal({
...
@@ -522,7 +528,11 @@ async function createComponentTreeInternal({
preloadCallbacks
,
preloadCallbacks
,
authInterrupts
,
authInterrupts
,
StreamingMetadata
,
StreamingMetadata
,
StreamingMetadataOutlet
,
// `StreamingMetadataOutlet` is used to conditionally throw. In the case of parallel routes we will have more than one page
// but we only want to throw on the first one.
StreamingMetadataOutlet
:
isChildrenRouteKey
?
StreamingMetadataOutlet
:
null
,
})
})
childCacheNodeSeedData
=
seedData
childCacheNodeSeedData
=
seedData
...
@@ -709,8 +719,10 @@ async function createComponentTreeInternal({
...
@@ -709,8 +719,10 @@ async function createComponentTreeInternal({
{
layerAssets
}
{
layerAssets
}
<
OutletBoundary
>
<
OutletBoundary
>
<
MetadataOutlet
ready=
{
getViewportReady
}
/>
<
MetadataOutlet
ready=
{
getViewportReady
}
/>
{
/* Blocking metadata outlet */
}
<
MetadataOutlet
ready=
{
getMetadataReady
}
/>
<
MetadataOutlet
ready=
{
getMetadataReady
}
/>
<
StreamingMetadataOutlet
/>
{
/* Streaming metadata outlet */
}
{
metadataOutlet
}
</
OutletBoundary
>
</
OutletBoundary
>
</
React
.
Fragment
>,
</
React
.
Fragment
>,
parallelRouteCacheNodeSeedData
,
parallelRouteCacheNodeSeedData
,
...
...
test/e2e/app-dir/metadata-streaming/app/notfound/boundary/not-found.tsx
0 → 100644
View file @
0b136b27
export
default
function
NotFound
()
{
return
<
h1
>
Custom Not Found
</
h1
>
}
export
const
metadata
=
{
title
:
'notfound title'
,
}
test/e2e/app-dir/metadata-streaming/app/notfound/boundary/page.tsx
0 → 100644
View file @
0b136b27
import
{
connection
}
from
'next/server'
import
{
notFound
}
from
'next/navigation'
export
default
function
Page
()
{
return
<
p
>
notfound page
</
p
>
}
export
async
function
generateMetadata
()
{
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2
*
1000
))
notFound
()
}
export
const
dynamic
=
'force-dynamic'
test/e2e/app-dir/metadata-streaming/app/notfound/page.tsx
View file @
0b136b27
...
@@ -2,12 +2,12 @@ import { connection } from 'next/server'
...
@@ -2,12 +2,12 @@ import { connection } from 'next/server'
import
{
notFound
}
from
'next/navigation'
import
{
notFound
}
from
'next/navigation'
export
default
function
Page
()
{
export
default
function
Page
()
{
return
<
p
>
notfound page
</
p
>
return
<
p
>
boundary
notfound page
</
p
>
}
}
export
async
function
generateMetadata
()
{
export
async
function
generateMetadata
()
{
await
connection
()
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2
*
10
00
))
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
5
00
))
notFound
()
notFound
()
}
}
...
...
test/e2e/app-dir/metadata-streaming/metadata-streaming.test.ts
View file @
0b136b27
...
@@ -121,6 +121,19 @@ describe('app-dir - metadata-streaming', () => {
...
@@ -121,6 +121,19 @@ describe('app-dir - metadata-streaming', () => {
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'index page'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'index page'
)
})
})
it
(
'should trigger custom not-found in the boundary'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/notfound/boundary'
)
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Custom Not Found'
)
})
it
(
'should not duplicate metadata with navigation API'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/notfound/boundary'
)
const
titleTags
=
await
browser
.
elementsByCss
(
'title'
)
expect
(
titleTags
.
length
).
toBe
(
1
)
})
it
(
'should render blocking 404 response status when html limited bots access notFound'
,
async
()
=>
{
it
(
'should render blocking 404 response status when html limited bots access notFound'
,
async
()
=>
{
const
{
status
}
=
await
next
.
fetch
(
'/notfound'
,
{
const
{
status
}
=
await
next
.
fetch
(
'/notfound'
,
{
headers
:
{
headers
:
{
...
...
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