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
2a4ed14c
Unverified
Commit
2a4ed14c
authored
Feb 28, 2025
by
Jiachi Liu
Committed by
GitHub
Feb 28, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] re-enable streaming metadata with PPR (#76119)
parent
bcb94e32
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
12 additions
and
104 deletions
+12
-104
index.ts
packages/next/src/build/index.ts
+1
-4
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+3
-14
work-store.ts
packages/next/src/server/async-storage/work-store.ts
+2
-0
base-server.ts
packages/next/src/server/base-server.ts
+2
-4
ppr-metadata-blocking-ppr-fallback.test.ts
...adata-blocking/ppr-metadata-blocking-ppr-fallback.test.ts
+1
-1
ppr-metadata-streaming.test.ts
...dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts
+1
-7
metadata-streaming-config-customized.test.ts
...aming-config/metadata-streaming-config-customized.test.ts
+1
-6
metadata-streaming-config.test.ts
...tadata-streaming-config/metadata-streaming-config.test.ts
+1
-7
layout.tsx
...dir/ppr-disable-streaming-metadata/app/dynamic/layout.tsx
+0
-5
page.tsx
...p-dir/ppr-disable-streaming-metadata/app/dynamic/page.tsx
+0
-12
layout.tsx
...ion/app-dir/ppr-disable-streaming-metadata/app/layout.tsx
+0
-16
layout.tsx
...app-dir/ppr-disable-streaming-metadata/app/ppr/layout.tsx
+0
-5
page.tsx
...n/app-dir/ppr-disable-streaming-metadata/app/ppr/page.tsx
+0
-13
next.config.js
...ion/app-dir/ppr-disable-streaming-metadata/next.config.js
+0
-10
No files found.
packages/next/src/build/index.ts
View file @
2a4ed14c
...
...
@@ -2776,10 +2776,7 @@ export default async function build(
},
// If it's PPR rendered non-static page, bypass the PPR cache when streaming metadata is enabled.
// This will skip the postpone data for those bots requests and instead produce a dynamic render.
...(
isRoutePPREnabled
&&
// Disable streaming metadata for PPR on deployment where we don't have the special env.
// TODO: enable streaming metadata in PPR mode by default once it's ready.
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
===
'true'
...(
isRoutePPREnabled
?
[
{
type
:
'header'
,
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
2a4ed14c
...
...
@@ -433,17 +433,6 @@ function NonIndex({ ctx }: { ctx: AppRenderContext }) {
return
null
}
function
getServeStreamingMetadata
(
ctx
:
AppRenderContext
)
{
const
isRoutePPREnabled
=
!!
ctx
.
renderOpts
.
experimental
.
isRoutePPREnabled
const
serveStreamingMetadata
=
!!
ctx
.
renderOpts
.
serveStreamingMetadata
// If the route is in PPR and the special env is not set, disable the streaming metadata.
// TODO: enable streaming metadata in PPR mode by default once it's ready.
if
(
isRoutePPREnabled
&&
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
!==
'true'
)
{
return
false
}
return
serveStreamingMetadata
}
/**
* This is used by server actions & client-side navigations to generate RSC data from a client-side request.
* This function is only called on "dynamic" requests (ie, there wasn't already a static response).
...
...
@@ -483,7 +472,7 @@ async function generateDynamicRSCPayload(
url
,
}
=
ctx
const
serveStreamingMetadata
=
getServeStreamingMetadata
(
ctx
)
const
serveStreamingMetadata
=
!!
ctx
.
renderOpts
.
serveStreamingMetadata
if
(
!
options
?.
skipFlight
)
{
const
preloadCallbacks
:
PreloadCallbacks
=
[]
...
...
@@ -803,7 +792,7 @@ async function getRSCPayload(
getDynamicParamFromSegment
,
query
)
const
serveStreamingMetadata
=
getServeStreamingMetadata
(
ctx
)
const
serveStreamingMetadata
=
!!
ctx
.
renderOpts
.
serveStreamingMetadata
const
searchParams
=
createServerSearchParamsForMetadata
(
query
,
workStore
)
const
{
...
...
@@ -941,7 +930,7 @@ async function getErrorRSCPayload(
workStore
,
}
=
ctx
const
serveStreamingMetadata
=
getServeStreamingMetadata
(
ctx
)
const
serveStreamingMetadata
=
!!
ctx
.
renderOpts
.
serveStreamingMetadata
const
searchParams
=
createServerSearchParamsForMetadata
(
query
,
workStore
)
const
{
MetadataTree
,
ViewportTree
}
=
createMetadataComponents
({
tree
,
...
...
packages/next/src/server/async-storage/work-store.ts
View file @
2a4ed14c
...
...
@@ -56,6 +56,7 @@ export type WorkStoreContext = {
RenderOpts
,
|
'assetPrefix'
|
'supportsDynamicResponse'
|
'shouldWaitOnAllReady'
|
'isRevalidate'
|
'nextExport'
|
'isDraftMode'
...
...
@@ -97,6 +98,7 @@ export function createWorkStore({
* coalescing, and ISR continue working as intended.
*/
const
isStaticGeneration
=
!
renderOpts
.
shouldWaitOnAllReady
&&
!
renderOpts
.
supportsDynamicResponse
&&
!
renderOpts
.
isDraftMode
&&
!
renderOpts
.
isServerAction
...
...
packages/next/src/server/base-server.ts
View file @
2a4ed14c
...
...
@@ -2484,10 +2484,8 @@ export default abstract class Server<
query
:
origQuery
,
})
const
shouldWaitOnAllReady
=
!
supportsDynamicResponse
||
// When html bots request PPR page, perform the full dynamic rendering.
(
isHtmlBot
&&
isRoutePPREnabled
)
// When html bots request PPR page, perform the full dynamic rendering.
const
shouldWaitOnAllReady
=
isHtmlBot
&&
isRoutePPREnabled
const
renderOpts
:
LoadedRenderOpts
=
{
...
components
,
...
...
test/e2e/app-dir/ppr-metadata-blocking/ppr-metadata-blocking-ppr-fallback.test.ts
View file @
2a4ed14c
...
...
@@ -4,10 +4,10 @@ function countSubstring(str: string, substr: string): number {
return
str
.
split
(
substr
).
length
-
1
}
// The default ppr-metadata-blocking is covered by test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts
describe
(
'ppr-metadata-blocking-ppr-fallback'
,
()
=>
{
const
{
next
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
// Need to skip deployment because the test uses the private env cannot be used in deployment
skipDeployment
:
true
,
env
:
{
__NEXT_EXPERIMENTAL_STATIC_SHELL_DEBUGGING
:
'1'
,
...
...
test/e2e/app-dir/ppr-metadata-streaming/ppr-metadata-streaming.test.ts
View file @
2a4ed14c
...
...
@@ -2,21 +2,15 @@ import { nextTestSetup } from 'e2e-utils'
import
cheerio
from
'cheerio'
import
{
assertNoConsoleErrors
}
from
'next-test-utils'
// TODO: remove this env once streaming metadata is available for ppr
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
=
'true'
function
countSubstring
(
str
:
string
,
substr
:
string
):
number
{
return
str
.
split
(
substr
).
length
-
1
}
describe
(
'ppr-metadata-streaming'
,
()
=>
{
const
{
next
,
isNextDev
,
isNextDeploy
,
skipped
}
=
nextTestSetup
({
const
{
next
,
isNextDev
,
isNextDeploy
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
})
if
(
skipped
)
return
// No dynamic APIs used in metadata
describe
(
'static metadata'
,
()
=>
{
it
(
'should generate metadata in head when page is fully static'
,
async
()
=>
{
...
...
test/production/app-dir/metadata-streaming-config/metadata-streaming-config-customized.test.ts
View file @
2a4ed14c
import
{
nextTestSetup
}
from
'e2e-utils'
// TODO: remove this env once streaming metadata is available for ppr
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
=
'true'
describe
(
'app-dir - metadata-streaming-config-customized'
,
()
=>
{
const
{
next
,
skipped
}
=
nextTestSetup
({
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
overrideFiles
:
{
...
...
@@ -19,8 +16,6 @@ describe('app-dir - metadata-streaming-config-customized', () => {
},
})
if
(
skipped
)
return
it
(
'should have the customized streaming metadata config output in routes-manifest.json'
,
async
()
=>
{
const
prerenderManifest
=
JSON
.
parse
(
await
next
.
readFile
(
'.next/prerender-manifest.json'
)
...
...
test/production/app-dir/metadata-streaming-config/metadata-streaming-config.test.ts
View file @
2a4ed14c
import
{
nextTestSetup
}
from
'e2e-utils'
// TODO: remove this env once streaming metadata is available for ppr
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
=
'true'
describe
(
'app-dir - metadata-streaming-config'
,
()
=>
{
const
{
next
,
skipped
}
=
nextTestSetup
({
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
})
if
(
skipped
)
return
it
(
'should have the default streaming metadata config output in routes-manifest.json'
,
async
()
=>
{
const
requiredServerFiles
=
JSON
.
parse
(
await
next
.
readFile
(
'.next/required-server-files.json'
)
...
...
test/production/app-dir/ppr-disable-streaming-metadata/app/dynamic/layout.tsx
deleted
100644 → 0
View file @
bcb94e32
import
{
Suspense
}
from
'react'
export
default
function
Root
({
children
})
{
return
<
Suspense
fallback=
{
<
p
>
Loading...
</
p
>
}
>
{
children
}
</
Suspense
>
}
test/production/app-dir/ppr-disable-streaming-metadata/app/dynamic/page.tsx
deleted
100644 → 0
View file @
bcb94e32
import
{
connection
}
from
'next/server'
export
default
async
function
Page
()
{
return
<
p
>
hello world
</
p
>
}
// Dynamic metadata
export
async
function
generateMetadata
()
{
await
connection
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1000
))
return
{
title
:
'dynamic-title'
}
}
test/production/app-dir/ppr-disable-streaming-metadata/app/layout.tsx
deleted
100644 → 0
View file @
bcb94e32
import
{
ReactNode
}
from
'react'
import
Link
from
'next/link'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
<
nav
>
<
Link
href=
"/ppr"
>
ppr
</
Link
>
<
Link
href=
"/dynamic"
>
dynamic
</
Link
>
</
nav
>
{
children
}
</
body
>
</
html
>
)
}
test/production/app-dir/ppr-disable-streaming-metadata/app/ppr/layout.tsx
deleted
100644 → 0
View file @
bcb94e32
import
{
Suspense
}
from
'react'
export
default
function
Root
({
children
})
{
return
<
Suspense
fallback=
{
<
p
>
Loading...
</
p
>
}
>
{
children
}
</
Suspense
>
}
test/production/app-dir/ppr-disable-streaming-metadata/app/ppr/page.tsx
deleted
100644 → 0
View file @
bcb94e32
import
{
connection
}
from
'next/server'
export
default
async
function
Page
()
{
await
connection
()
return
<
p
>
ppr
</
p
>
}
export
async
function
generateMetadata
()
{
await
connection
()
return
{
title
:
'ppr-title'
}
}
export
const
experimental_ppr
=
true
test/production/app-dir/ppr-disable-streaming-metadata/next.config.js
deleted
100644 → 0
View file @
bcb94e32
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
experimental
:
{
ppr
:
'incremental'
,
},
}
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