Unverified Commit 2a4ed14c authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] re-enable streaming metadata with PPR (#76119)

parent bcb94e32
......@@ -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',
......
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
......@@ -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',
......
......@@ -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 () => {
......
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')
......
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')
......
import { Suspense } from 'react'
export default function Root({ children }) {
return <Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
}
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' }
}
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>
)
}
import { Suspense } from 'react'
export default function Root({ children }) {
return <Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
}
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
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
ppr: 'incremental',
},
}
module.exports = nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment