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
b3055c3a
Unverified
Commit
b3055c3a
authored
Jan 24, 2025
by
Jiachi Liu
Committed by
GitHub
Jan 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] keep blocking metadata rendered in head (#75227)
parent
bf726d3c
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
403 additions
and
55 deletions
+403
-55
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+58
-45
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+5
-5
walk-tree-with-flight-router-state.tsx
.../server/app-render/walk-tree-with-flight-router-state.tsx
+4
-4
streaming-metadata.ts
packages/next/src/server/lib/streaming-metadata.ts
+4
-1
layout.tsx
test/e2e/app-dir/metadata-static-generation/app/layout.tsx
+29
-0
page.tsx
test/e2e/app-dir/metadata-static-generation/app/page.tsx
+11
-0
page.tsx
...tadata-static-generation/app/suspenseful/dynamic/page.tsx
+14
-0
layout.tsx
...dir/metadata-static-generation/app/suspenseful/layout.tsx
+9
-0
page.tsx
...etadata-static-generation/app/suspenseful/static/page.tsx
+10
-0
metadata-static-generation.test.ts
...data-static-generation/metadata-static-generation.test.ts
+48
-0
next.config.js
test/e2e/app-dir/metadata-static-generation/next.config.js
+6
-0
layout.tsx
...p-dir/metadata-streaming-static-generation/app/layout.tsx
+29
-0
page.tsx
...app-dir/metadata-streaming-static-generation/app/page.tsx
+10
-0
page.tsx
...ata-streaming-static-generation/app/slow/dynamic/page.tsx
+13
-0
page.tsx
...data-streaming-static-generation/app/slow/static/page.tsx
+10
-0
page.tsx
...eaming-static-generation/app/suspenseful/dynamic/page.tsx
+14
-0
layout.tsx
...ta-streaming-static-generation/app/suspenseful/layout.tsx
+9
-0
page.tsx
...reaming-static-generation/app/suspenseful/static/page.tsx
+10
-0
metadata-streaming-static-generation.test.ts
...c-generation/metadata-streaming-static-generation.test.ts
+100
-0
next.config.js
...p-dir/metadata-streaming-static-generation/next.config.js
+10
-0
No files found.
packages/next/src/server/app-render/app-render.tsx
View file @
b3055c3a
...
@@ -230,8 +230,7 @@ interface ParseRequestHeadersOptions {
...
@@ -230,8 +230,7 @@ interface ParseRequestHeadersOptions {
readonly
isRoutePPREnabled
:
boolean
readonly
isRoutePPREnabled
:
boolean
}
}
const
flightDataPathMetadataKey
=
'h'
const
flightDataPathHeadKey
=
'h'
const
flightDataPathViewportKey
=
'v'
interface
ParsedRequestHeaders
{
interface
ParsedRequestHeaders
{
/**
/**
...
@@ -316,18 +315,30 @@ function createNotFoundLoaderTree(loaderTree: LoaderTree): LoaderTree {
...
@@ -316,18 +315,30 @@ function createNotFoundLoaderTree(loaderTree: LoaderTree): LoaderTree {
]
]
}
}
function
create
SuspenseyMetadata
(
function
create
DivergedMetadataComponents
(
Metadata
:
React
.
ComponentType
<
{}
>
,
Metadata
:
React
.
ComponentType
<
{}
>
,
serveStreamingMetadata
:
boolean
serveStreamingMetadata
:
boolean
):
React
.
ComponentType
<
{}
>
{
):
{
return
()
=>
StaticMetadata
:
React
.
ComponentType
<
{}
>
serveStreamingMetadata
?
(
StreamingMetadata
:
React
.
ComponentType
<
{}
>
<
React
.
Suspense
fallback=
{
null
}
>
}
{
<
Metadata
/>
const
EmptyMetadata
=
()
=>
null
</
React
.
Suspense
>
const
StreamingMetadata
:
React
.
ComponentType
<
{}
>
=
serveStreamingMetadata
)
:
(
?
()
=>
(
<
Metadata
/>
<
React
.
Suspense
fallback=
{
null
}
>
)
<
Metadata
/>
</
React
.
Suspense
>
)
:
EmptyMetadata
const
StaticMetadata
:
React
.
ComponentType
<
{}
>
=
serveStreamingMetadata
?
EmptyMetadata
:
Metadata
return
{
StaticMetadata
,
StreamingMetadata
,
}
}
}
/**
/**
...
@@ -485,14 +496,13 @@ async function generateDynamicRSCPayload(
...
@@ -485,14 +496,13 @@ async function generateDynamicRSCPayload(
serveStreamingMetadata
:
!!
ctx
.
renderOpts
.
serveStreamingMetadata
,
serveStreamingMetadata
:
!!
ctx
.
renderOpts
.
serveStreamingMetadata
,
})
})
const
MetadataComponent
=
createSuspenseyMetadata
(()
=>
{
const
{
StreamingMetadata
,
StaticMetadata
}
=
return
(
createDivergedMetadataComponents
(()
=>
{
<
React
.
Fragment
key=
{
flightDataPathMetadataKey
}
>
return
(
{
/* Adding requestId as react key to make metadata remount for each render */
}
// Adding requestId as react key to make metadata remount for each render
<
MetadataTree
key=
{
requestId
}
/>
<
MetadataTree
key=
{
requestId
}
/>
</
React
.
Fragment
>
)
)
},
!!
ctx
.
renderOpts
.
serveStreamingMetadata
)
},
!!
ctx
.
renderOpts
.
serveStreamingMetadata
)
flightData
=
(
flightData
=
(
await
walkTreeWithFlightRouterState
({
await
walkTreeWithFlightRouterState
({
...
@@ -502,11 +512,12 @@ async function generateDynamicRSCPayload(
...
@@ -502,11 +512,12 @@ async function generateDynamicRSCPayload(
flightRouterState
,
flightRouterState
,
// For flight, render metadata inside leaf page
// For flight, render metadata inside leaf page
rscHead
:
(
rscHead
:
(
<
React
.
Fragment
key=
{
flightDataPath
Viewport
Key
}
>
<
React
.
Fragment
key=
{
flightDataPath
Head
Key
}
>
{
/* noindex needs to be blocking */
}
{
/* noindex needs to be blocking */
}
<
NonIndex
ctx=
{
ctx
}
/>
<
NonIndex
ctx=
{
ctx
}
/>
{
/* Adding requestId as react key to make metadata remount for each render */
}
{
/* Adding requestId as react key to make metadata remount for each render */
}
<
ViewportTree
key=
{
requestId
}
/>
<
ViewportTree
key=
{
requestId
}
/>
<
StaticMetadata
/>
</
React
.
Fragment
>
</
React
.
Fragment
>
),
),
injectedCSS
:
new
Set
(),
injectedCSS
:
new
Set
(),
...
@@ -516,7 +527,7 @@ async function generateDynamicRSCPayload(
...
@@ -516,7 +527,7 @@ async function generateDynamicRSCPayload(
getViewportReady
,
getViewportReady
,
getMetadataReady
,
getMetadataReady
,
preloadCallbacks
,
preloadCallbacks
,
MetadataComponent
,
StreamingMetadata
,
})
})
).
map
((
path
)
=>
path
.
slice
(
1
))
// remove the '' (root) segment
).
map
((
path
)
=>
path
.
slice
(
1
))
// remove the '' (root) segment
}
}
...
@@ -794,14 +805,13 @@ async function getRSCPayload(
...
@@ -794,14 +805,13 @@ async function getRSCPayload(
const
preloadCallbacks
:
PreloadCallbacks
=
[]
const
preloadCallbacks
:
PreloadCallbacks
=
[]
const
MetadataComponent
=
createSuspenseyMetadata
(()
=>
{
const
{
StreamingMetadata
,
StaticMetadata
}
=
return
(
createDivergedMetadataComponents
(()
=>
{
<
React
.
Fragment
key=
{
flightDataPathMetadataKey
}
>
return
(
{
/* Not add requestId as react key to ensure segment prefetch could result consistently if nothing changed */
}
// Not add requestId as react key to ensure segment prefetch could result consistently if nothing changed
<
MetadataTree
/>
<
MetadataTree
/>
</
React
.
Fragment
>
)
)
},
!!
ctx
.
renderOpts
.
serveStreamingMetadata
)
},
!!
ctx
.
renderOpts
.
serveStreamingMetadata
)
const
seedData
=
await
createComponentTree
({
const
seedData
=
await
createComponentTree
({
ctx
,
ctx
,
...
@@ -816,7 +826,7 @@ async function getRSCPayload(
...
@@ -816,7 +826,7 @@ async function getRSCPayload(
missingSlots
,
missingSlots
,
preloadCallbacks
,
preloadCallbacks
,
authInterrupts
:
ctx
.
renderOpts
.
experimental
.
authInterrupts
,
authInterrupts
:
ctx
.
renderOpts
.
experimental
.
authInterrupts
,
MetadataComponent
,
StreamingMetadata
,
})
})
// When the `vary` response header is present with `Next-URL`, that means there's a chance
// When the `vary` response header is present with `Next-URL`, that means there's a chance
...
@@ -826,10 +836,11 @@ async function getRSCPayload(
...
@@ -826,10 +836,11 @@ async function getRSCPayload(
const
couldBeIntercepted
=
const
couldBeIntercepted
=
typeof
varyHeader
===
'string'
&&
varyHeader
.
includes
(
NEXT_URL
)
typeof
varyHeader
===
'string'
&&
varyHeader
.
includes
(
NEXT_URL
)
const
initialHead
Viewport
=
(
const
initialHead
=
(
<
React
.
Fragment
key=
{
flightDataPath
Viewport
Key
}
>
<
React
.
Fragment
key=
{
flightDataPath
Head
Key
}
>
<
NonIndex
ctx=
{
ctx
}
/>
<
NonIndex
ctx=
{
ctx
}
/>
<
ViewportTree
key=
{
ctx
.
requestId
}
/>
<
ViewportTree
key=
{
ctx
.
requestId
}
/>
<
StaticMetadata
/>
</
React
.
Fragment
>
</
React
.
Fragment
>
)
)
...
@@ -856,7 +867,7 @@ async function getRSCPayload(
...
@@ -856,7 +867,7 @@ async function getRSCPayload(
[
[
initialTree
,
initialTree
,
seedData
,
seedData
,
[
initialHeadViewport
,
null
]
,
initialHead
,
isPossiblyPartialHead
,
isPossiblyPartialHead
,
]
as
FlightDataPath
,
]
as
FlightDataPath
,
],
],
...
@@ -919,24 +930,26 @@ async function getErrorRSCPayload(
...
@@ -919,24 +930,26 @@ async function getErrorRSCPayload(
serveStreamingMetadata
:
!!
ctx
.
renderOpts
.
serveStreamingMetadata
,
serveStreamingMetadata
:
!!
ctx
.
renderOpts
.
serveStreamingMetadata
,
})
})
const
ErrorMetadataComponent
=
createSuspenseyMetadata
(
const
{
StreamingMetadata
,
StaticMetadata
}
=
()
=>
(
createDivergedMetadataComponents
(
<
React
.
Fragment
key=
{
flightDataPathMetadataKey
}
>
()
=>
(
{
/* Adding requestId as react key to make metadata remount for each render */
}
<
React
.
Fragment
key=
{
flightDataPathHeadKey
}
>
<
MetadataTree
key=
{
requestId
}
/>
{
/* Adding requestId as react key to make metadata remount for each render */
}
</
React
.
Fragment
>
<
MetadataTree
key=
{
requestId
}
/>
),
</
React
.
Fragment
>
!!
ctx
.
renderOpts
.
serveStreamingMetadata
),
)
!!
ctx
.
renderOpts
.
serveStreamingMetadata
)
const
initialHead
Viewport
=
(
const
initialHead
=
(
<
React
.
Fragment
key=
{
flightDataPath
Viewport
Key
}
>
<
React
.
Fragment
key=
{
flightDataPath
Head
Key
}
>
<
NonIndex
ctx=
{
ctx
}
/>
<
NonIndex
ctx=
{
ctx
}
/>
{
/* Adding requestId as react key to make metadata remount for each render */
}
{
/* Adding requestId as react key to make metadata remount for each render */
}
<
ViewportTree
key=
{
requestId
}
/>
<
ViewportTree
key=
{
requestId
}
/>
{
process
.
env
.
NODE_ENV
===
'development'
&&
(
{
process
.
env
.
NODE_ENV
===
'development'
&&
(
<
meta
name=
"next-error"
content=
"not-found"
/>
<
meta
name=
"next-error"
content=
"not-found"
/>
)
}
)
}
<
StaticMetadata
/>
</
React
.
Fragment
>
</
React
.
Fragment
>
)
)
...
@@ -957,7 +970,7 @@ async function getErrorRSCPayload(
...
@@ -957,7 +970,7 @@ async function getErrorRSCPayload(
initialTree
[
0
],
initialTree
[
0
],
<
html
id=
"__next_error__"
>
<
html
id=
"__next_error__"
>
<
head
>
<
head
>
<
ErrorMetadataComponent
/>
<
StreamingMetadata
/>
</
head
>
</
head
>
<
body
>
<
body
>
{
process
.
env
.
NODE_ENV
!==
'production'
&&
err
?
(
{
process
.
env
.
NODE_ENV
!==
'production'
&&
err
?
(
...
@@ -989,7 +1002,7 @@ async function getErrorRSCPayload(
...
@@ -989,7 +1002,7 @@ async function getErrorRSCPayload(
[
[
initialTree
,
initialTree
,
seedData
,
seedData
,
[
initialHeadViewport
,
null
]
,
initialHead
,
isPossiblyPartialHead
,
isPossiblyPartialHead
,
]
as
FlightDataPath
,
]
as
FlightDataPath
,
],
],
...
...
packages/next/src/server/app-render/create-component-tree.tsx
View file @
b3055c3a
...
@@ -36,7 +36,7 @@ export function createComponentTree(props: {
...
@@ -36,7 +36,7 @@ export function createComponentTree(props: {
missingSlots
?:
Set
<
string
>
missingSlots
?:
Set
<
string
>
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
authInterrupts
:
boolean
authInterrupts
:
boolean
MetadataComponent
:
React
.
ComponentType
<
{}
>
StreamingMetadata
:
React
.
ComponentType
<
{}
>
}):
Promise
<
CacheNodeSeedData
>
{
}):
Promise
<
CacheNodeSeedData
>
{
return
getTracer
().
trace
(
return
getTracer
().
trace
(
NextNodeServerSpan
.
createComponentTree
,
NextNodeServerSpan
.
createComponentTree
,
...
@@ -72,7 +72,7 @@ async function createComponentTreeInternal({
...
@@ -72,7 +72,7 @@ async function createComponentTreeInternal({
missingSlots
,
missingSlots
,
preloadCallbacks
,
preloadCallbacks
,
authInterrupts
,
authInterrupts
,
MetadataComponent
,
StreamingMetadata
,
}:
{
}:
{
loaderTree
:
LoaderTree
loaderTree
:
LoaderTree
parentParams
:
Params
parentParams
:
Params
...
@@ -86,7 +86,7 @@ async function createComponentTreeInternal({
...
@@ -86,7 +86,7 @@ async function createComponentTreeInternal({
missingSlots
?:
Set
<
string
>
missingSlots
?:
Set
<
string
>
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
authInterrupts
:
boolean
authInterrupts
:
boolean
MetadataComponent
:
React
.
ComponentType
<
{}
>
StreamingMetadata
:
React
.
ComponentType
<
{}
>
}):
Promise
<
CacheNodeSeedData
>
{
}):
Promise
<
CacheNodeSeedData
>
{
const
{
const
{
renderOpts
:
{
nextConfigOutput
,
experimental
},
renderOpts
:
{
nextConfigOutput
,
experimental
},
...
@@ -395,7 +395,7 @@ async function createComponentTreeInternal({
...
@@ -395,7 +395,7 @@ 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
metadata
=
const
metadata
=
actualSegment
!==
DEFAULT_SEGMENT_KEY
?
<
MetadataComponent
/>
:
undefined
actualSegment
!==
DEFAULT_SEGMENT_KEY
?
<
StreamingMetadata
/>
:
undefined
const
notFoundElement
=
NotFound
?
(
const
notFoundElement
=
NotFound
?
(
<>
<>
...
@@ -516,7 +516,7 @@ async function createComponentTreeInternal({
...
@@ -516,7 +516,7 @@ async function createComponentTreeInternal({
missingSlots
,
missingSlots
,
preloadCallbacks
,
preloadCallbacks
,
authInterrupts
,
authInterrupts
,
MetadataComponent
,
StreamingMetadata
,
})
})
childCacheNodeSeedData
=
seedData
childCacheNodeSeedData
=
seedData
...
...
packages/next/src/server/app-render/walk-tree-with-flight-router-state.tsx
View file @
b3055c3a
...
@@ -40,7 +40,7 @@ export async function walkTreeWithFlightRouterState({
...
@@ -40,7 +40,7 @@ export async function walkTreeWithFlightRouterState({
getMetadataReady
,
getMetadataReady
,
ctx
,
ctx
,
preloadCallbacks
,
preloadCallbacks
,
MetadataComponent
,
StreamingMetadata
,
}:
{
}:
{
loaderTreeToFilter
:
LoaderTree
loaderTreeToFilter
:
LoaderTree
parentParams
:
{
[
key
:
string
]:
string
|
string
[]
}
parentParams
:
{
[
key
:
string
]:
string
|
string
[]
}
...
@@ -55,7 +55,7 @@ export async function walkTreeWithFlightRouterState({
...
@@ -55,7 +55,7 @@ export async function walkTreeWithFlightRouterState({
getViewportReady
:
()
=>
Promise
<
void
>
getViewportReady
:
()
=>
Promise
<
void
>
ctx
:
AppRenderContext
ctx
:
AppRenderContext
preloadCallbacks
:
PreloadCallbacks
preloadCallbacks
:
PreloadCallbacks
MetadataComponent
:
React
.
ComponentType
<
{}
>
StreamingMetadata
:
React
.
ComponentType
<
{}
>
}):
Promise
<
FlightDataPath
[]
>
{
}):
Promise
<
FlightDataPath
[]
>
{
const
{
const
{
renderOpts
:
{
nextFontManifest
,
experimental
},
renderOpts
:
{
nextFontManifest
,
experimental
},
...
@@ -204,7 +204,7 @@ export async function walkTreeWithFlightRouterState({
...
@@ -204,7 +204,7 @@ export async function walkTreeWithFlightRouterState({
getMetadataReady
,
getMetadataReady
,
preloadCallbacks
,
preloadCallbacks
,
authInterrupts
:
experimental
.
authInterrupts
,
authInterrupts
:
experimental
.
authInterrupts
,
MetadataComponent
,
StreamingMetadata
,
}
}
)
)
...
@@ -264,7 +264,7 @@ export async function walkTreeWithFlightRouterState({
...
@@ -264,7 +264,7 @@ export async function walkTreeWithFlightRouterState({
getViewportReady
,
getViewportReady
,
getMetadataReady
,
getMetadataReady
,
preloadCallbacks
,
preloadCallbacks
,
MetadataComponent
,
StreamingMetadata
,
})
})
for
(
const
subPath
of
subPaths
)
{
for
(
const
subPath
of
subPaths
)
{
...
...
packages/next/src/server/lib/streaming-metadata.ts
View file @
b3055c3a
...
@@ -18,5 +18,8 @@ export function shouldServeStreamingMetadata(
...
@@ -18,5 +18,8 @@ export function shouldServeStreamingMetadata(
htmlLimitedBots
||
HTML_LIMITED_BOT_UA_RE_STRING
,
htmlLimitedBots
||
HTML_LIMITED_BOT_UA_RE_STRING
,
'i'
'i'
)
)
return
!
blockingMetadataUARegex
.
test
(
userAgent
)
return
(
// When it's static generation, userAgents are not available - do not serve streaming metadata
!!
userAgent
&&
!
blockingMetadataUARegex
.
test
(
userAgent
)
)
}
}
test/e2e/app-dir/metadata-static-generation/app/layout.tsx
0 → 100644
View file @
b3055c3a
import
Link
from
'next/link'
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
<
div
>
<
Link
href=
"/slow"
id=
"to-slow"
>
{
`to /slow`
}
</
Link
>
<
br
/>
<
Link
href=
"/"
id=
"to-home"
>
{
`to /`
}
</
Link
>
<
br
/>
<
Link
href=
"/suspenseful/dynamic"
id=
"to-suspenseful-dynamic"
>
{
`to /suspenseful/dynamic`
}
</
Link
>
<
br
/>
<
Link
href=
"/suspenseful/static"
id=
"to-suspenseful-static"
>
{
`to /suspenseful/static`
}
</
Link
>
</
div
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/metadata-static-generation/app/page.tsx
0 → 100644
View file @
b3055c3a
export
default
function
Page
()
{
return
<
p
>
index
</
p
>
}
export
async
function
generateMetadata
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'index page'
,
description
:
'index page description'
,
}
}
test/e2e/app-dir/metadata-static-generation/app/suspenseful/dynamic/page.tsx
0 → 100644
View file @
b3055c3a
import
{
connection
}
from
'next/server'
export
default
async
function
Page
()
{
await
connection
()
return
<
p
>
suspenseful - dynamic
</
p
>
}
export
async
function
generateMetadata
()
{
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'suspenseful page - dynamic'
,
}
}
test/e2e/app-dir/metadata-static-generation/app/suspenseful/layout.tsx
0 → 100644
View file @
b3055c3a
import
{
Suspense
}
from
'react'
export
default
function
Layout
({
children
})
{
return
(
<
div
className=
"suspenseful-layout"
>
<
Suspense
>
{
children
}
</
Suspense
>
</
div
>
)
}
test/e2e/app-dir/metadata-static-generation/app/suspenseful/static/page.tsx
0 → 100644
View file @
b3055c3a
export
default
async
function
Page
()
{
return
<
p
>
suspenseful - static
</
p
>
}
export
async
function
generateMetadata
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'suspenseful page - static'
,
}
}
test/e2e/app-dir/metadata-static-generation/metadata-static-generation.test.ts
0 → 100644
View file @
b3055c3a
import
{
nextTestSetup
}
from
'e2e-utils'
const
isPPREnabled
=
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
===
'true'
describe
(
'app-dir - metadata-static-generation'
,
()
=>
{
const
{
next
,
isNextStart
}
=
nextTestSetup
({
files
:
__dirname
,
})
// /suspenseful/dynamic will behave differently when PPR is enabled.
// We'll visit PPR tests in the new test suite.
if
(
isPPREnabled
)
{
it
(
'skip ppr test'
,
()
=>
{})
return
}
if
(
isNextStart
)
{
// Precondition for the following tests in build mode
it
(
'should generate all pages static'
,
async
()
=>
{
const
prerenderManifest
=
JSON
.
parse
(
await
next
.
readFile
(
'.next/prerender-manifest.json'
)
)
const
staticRoutes
=
prerenderManifest
.
routes
expect
(
Object
.
keys
(
staticRoutes
).
sort
()).
toEqual
([
'/'
,
'/suspenseful/static'
,
])
})
}
it
(
'should contain async generated metadata in head for simple static page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'index page'
)
expect
(
$
(
'head meta[name="description"]'
).
attr
(
'content'
)).
toBe
(
'index page description'
)
})
it
(
'should contain async generated metadata in head static page with suspenseful content'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/static'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'suspenseful page - static'
)
})
it
(
'should contain async generated metadata in head for dynamic page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/dynamic'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'suspenseful page - dynamic'
)
})
})
test/e2e/app-dir/metadata-static-generation/next.config.js
0 → 100644
View file @
b3055c3a
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
module
.
exports
=
nextConfig
test/e2e/app-dir/metadata-streaming-static-generation/app/layout.tsx
0 → 100644
View file @
b3055c3a
import
Link
from
'next/link'
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
<
div
>
<
Link
href=
"/slow"
id=
"to-slow"
>
{
`to /slow`
}
</
Link
>
<
br
/>
<
Link
href=
"/"
id=
"to-home"
>
{
`to /`
}
</
Link
>
<
br
/>
<
Link
href=
"/suspenseful/dynamic"
id=
"to-suspenseful-dynamic"
>
{
`to /suspenseful/dynamic`
}
</
Link
>
<
br
/>
<
Link
href=
"/suspenseful/static"
id=
"to-suspenseful-static"
>
{
`to /suspenseful/static`
}
</
Link
>
</
div
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/metadata-streaming-static-generation/app/page.tsx
0 → 100644
View file @
b3055c3a
export
default
function
Page
()
{
return
<
p
>
index
</
p
>
}
export
async
function
generateMetadata
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'index page'
,
}
}
test/e2e/app-dir/metadata-streaming-static-generation/app/slow/dynamic/page.tsx
0 → 100644
View file @
b3055c3a
import
{
connection
}
from
'next/server'
export
default
function
Page
()
{
return
<
p
>
slow dynamic
</
p
>
}
export
async
function
generateMetadata
()
{
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
3
*
1000
))
return
{
title
:
'slow page - dynamic'
,
}
}
test/e2e/app-dir/metadata-streaming-static-generation/app/slow/static/page.tsx
0 → 100644
View file @
b3055c3a
export
default
function
Page
()
{
return
<
p
>
slow static
</
p
>
}
export
async
function
generateMetadata
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
3
*
1000
))
return
{
title
:
'slow page - static'
,
}
}
test/e2e/app-dir/metadata-streaming-static-generation/app/suspenseful/dynamic/page.tsx
0 → 100644
View file @
b3055c3a
import
{
connection
}
from
'next/server'
export
default
async
function
Page
()
{
await
connection
()
return
<
p
>
suspenseful - dynamic
</
p
>
}
export
async
function
generateMetadata
()
{
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'suspenseful page - dynamic'
,
}
}
test/e2e/app-dir/metadata-streaming-static-generation/app/suspenseful/layout.tsx
0 → 100644
View file @
b3055c3a
import
{
Suspense
}
from
'react'
export
default
function
Layout
({
children
})
{
return
(
<
div
className=
"suspenseful-layout"
>
<
Suspense
>
{
children
}
</
Suspense
>
</
div
>
)
}
test/e2e/app-dir/metadata-streaming-static-generation/app/suspenseful/static/page.tsx
0 → 100644
View file @
b3055c3a
export
default
async
function
Page
()
{
return
<
p
>
suspenseful - static
</
p
>
}
export
async
function
generateMetadata
()
{
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
*
1000
))
return
{
title
:
'suspenseful page - static'
,
}
}
test/e2e/app-dir/metadata-streaming-static-generation/metadata-streaming-static-generation.test.ts
0 → 100644
View file @
b3055c3a
import
{
nextTestSetup
}
from
'e2e-utils'
const
isPPREnabled
=
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
===
'true'
describe
(
'app-dir - metadata-streaming-static-generation'
,
()
=>
{
const
{
next
,
isNextDev
,
isNextStart
}
=
nextTestSetup
({
files
:
__dirname
,
})
// /suspenseful/dynamic will behave differently when PPR is enabled.
// We'll visit PPR tests in the new test suite.
if
(
isPPREnabled
)
{
it
(
'skip ppr test'
,
()
=>
{})
return
}
if
(
isNextStart
)
{
// Precondition for the following tests in build mode
it
(
'should generate all pages static'
,
async
()
=>
{
const
prerenderManifest
=
JSON
.
parse
(
await
next
.
readFile
(
'.next/prerender-manifest.json'
)
)
const
staticRoutes
=
prerenderManifest
.
routes
expect
(
Object
.
keys
(
staticRoutes
).
sort
()).
toEqual
([
'/'
,
'/slow/static'
,
'/suspenseful/static'
,
])
})
}
if
(
isNextDev
)
{
// In development it's still dynamic rendering that metadata will be inserted into body
describe
(
'static pages (development)'
,
()
=>
{
it
(
'should contain async generated metadata in body for simple static page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/'
)
expect
(
$
(
'body title'
).
text
()).
toBe
(
'index page'
)
})
it
(
'should contain async generated metadata in body for slow static page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/slow/static'
)
expect
(
$
(
'body title'
).
text
()).
toBe
(
'slow page - static'
)
})
it
(
'should contain async generated metadata in body static page with suspenseful content'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/static'
)
expect
(
$
(
'body title'
).
text
()).
toBe
(
'suspenseful page - static'
)
})
})
}
else
{
describe
(
'static pages (production)'
,
()
=>
{
it
(
'should contain async generated metadata in head for simple static page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'index page'
)
})
it
(
'should contain async generated metadata in head for slow static page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/slow/static'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'slow page - static'
)
})
it
(
'should contain async generated metadata in head static page with suspenseful content'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/static'
)
expect
(
$
(
'head title'
).
text
()).
toBe
(
'suspenseful page - static'
)
})
})
}
describe
(
'dynamic pages'
,
()
=>
{
it
(
'should contain async generated metadata in body for simple dynamics page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/dynamic'
)
expect
(
$
(
'body title'
).
text
()).
toBe
(
'suspenseful page - dynamic'
)
})
it
(
'should contain async generated metadata in body for suspenseful dynamic page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/slow/dynamic'
)
expect
(
$
(
'body title'
).
text
()).
toBe
(
'slow page - dynamic'
)
})
})
describe
(
'dynamic pages with html limited bots'
,
()
=>
{
it
(
'should contain async generated metadata in head for simple dynamics page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/suspenseful/dynamic'
,
undefined
,
{
headers
:
{
'User-Agent'
:
'Discordbot/2.0;'
,
},
})
expect
(
$
(
'head title'
).
text
()).
toBe
(
'suspenseful page - dynamic'
)
})
it
(
'should contain async generated metadata in head for suspenseful dynamic page'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/slow/dynamic'
,
undefined
,
{
headers
:
{
'User-Agent'
:
'Discordbot/2.0;'
,
},
})
expect
(
$
(
'head title'
).
text
()).
toBe
(
'slow page - dynamic'
)
})
})
})
test/e2e/app-dir/metadata-streaming-static-generation/next.config.js
0 → 100644
View file @
b3055c3a
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
experimental
:
{
streamingMetadata
:
true
,
},
}
module
.
exports
=
nextConfig
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