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( ...@@ -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. // 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. // This will skip the postpone data for those bots requests and instead produce a dynamic render.
...(isRoutePPREnabled && ...(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'
? [ ? [
{ {
type: 'header', type: 'header',
......
...@@ -433,17 +433,6 @@ function NonIndex({ ctx }: { ctx: AppRenderContext }) { ...@@ -433,17 +433,6 @@ function NonIndex({ ctx }: { ctx: AppRenderContext }) {
return null 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 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). * This function is only called on "dynamic" requests (ie, there wasn't already a static response).
...@@ -483,7 +472,7 @@ async function generateDynamicRSCPayload( ...@@ -483,7 +472,7 @@ async function generateDynamicRSCPayload(
url, url,
} = ctx } = ctx
const serveStreamingMetadata = getServeStreamingMetadata(ctx) const serveStreamingMetadata = !!ctx.renderOpts.serveStreamingMetadata
if (!options?.skipFlight) { if (!options?.skipFlight) {
const preloadCallbacks: PreloadCallbacks = [] const preloadCallbacks: PreloadCallbacks = []
...@@ -803,7 +792,7 @@ async function getRSCPayload( ...@@ -803,7 +792,7 @@ async function getRSCPayload(
getDynamicParamFromSegment, getDynamicParamFromSegment,
query query
) )
const serveStreamingMetadata = getServeStreamingMetadata(ctx) const serveStreamingMetadata = !!ctx.renderOpts.serveStreamingMetadata
const searchParams = createServerSearchParamsForMetadata(query, workStore) const searchParams = createServerSearchParamsForMetadata(query, workStore)
const { const {
...@@ -941,7 +930,7 @@ async function getErrorRSCPayload( ...@@ -941,7 +930,7 @@ async function getErrorRSCPayload(
workStore, workStore,
} = ctx } = ctx
const serveStreamingMetadata = getServeStreamingMetadata(ctx) const serveStreamingMetadata = !!ctx.renderOpts.serveStreamingMetadata
const searchParams = createServerSearchParamsForMetadata(query, workStore) const searchParams = createServerSearchParamsForMetadata(query, workStore)
const { MetadataTree, ViewportTree } = createMetadataComponents({ const { MetadataTree, ViewportTree } = createMetadataComponents({
tree, tree,
......
...@@ -56,6 +56,7 @@ export type WorkStoreContext = { ...@@ -56,6 +56,7 @@ export type WorkStoreContext = {
RenderOpts, RenderOpts,
| 'assetPrefix' | 'assetPrefix'
| 'supportsDynamicResponse' | 'supportsDynamicResponse'
| 'shouldWaitOnAllReady'
| 'isRevalidate' | 'isRevalidate'
| 'nextExport' | 'nextExport'
| 'isDraftMode' | 'isDraftMode'
...@@ -97,6 +98,7 @@ export function createWorkStore({ ...@@ -97,6 +98,7 @@ export function createWorkStore({
* coalescing, and ISR continue working as intended. * coalescing, and ISR continue working as intended.
*/ */
const isStaticGeneration = const isStaticGeneration =
!renderOpts.shouldWaitOnAllReady &&
!renderOpts.supportsDynamicResponse && !renderOpts.supportsDynamicResponse &&
!renderOpts.isDraftMode && !renderOpts.isDraftMode &&
!renderOpts.isServerAction !renderOpts.isServerAction
......
...@@ -2484,10 +2484,8 @@ export default abstract class Server< ...@@ -2484,10 +2484,8 @@ export default abstract class Server<
query: origQuery, query: origQuery,
}) })
const shouldWaitOnAllReady =
!supportsDynamicResponse ||
// When html bots request PPR page, perform the full dynamic rendering. // When html bots request PPR page, perform the full dynamic rendering.
(isHtmlBot && isRoutePPREnabled) const shouldWaitOnAllReady = isHtmlBot && isRoutePPREnabled
const renderOpts: LoadedRenderOpts = { const renderOpts: LoadedRenderOpts = {
...components, ...components,
......
...@@ -4,10 +4,10 @@ function countSubstring(str: string, substr: string): number { ...@@ -4,10 +4,10 @@ function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1 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', () => { describe('ppr-metadata-blocking-ppr-fallback', () => {
const { next, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
// Need to skip deployment because the test uses the private env cannot be used in deployment
skipDeployment: true, skipDeployment: true,
env: { env: {
__NEXT_EXPERIMENTAL_STATIC_SHELL_DEBUGGING: '1', __NEXT_EXPERIMENTAL_STATIC_SHELL_DEBUGGING: '1',
......
...@@ -2,21 +2,15 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -2,21 +2,15 @@ import { nextTestSetup } from 'e2e-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { assertNoConsoleErrors } from 'next-test-utils' 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 { function countSubstring(str: string, substr: string): number {
return str.split(substr).length - 1 return str.split(substr).length - 1
} }
describe('ppr-metadata-streaming', () => { describe('ppr-metadata-streaming', () => {
const { next, isNextDev, isNextDeploy, skipped } = nextTestSetup({ const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
}) })
if (skipped) return
// No dynamic APIs used in metadata // No dynamic APIs used in metadata
describe('static metadata', () => { describe('static metadata', () => {
it('should generate metadata in head when page is fully static', async () => { it('should generate metadata in head when page is fully static', async () => {
......
import { nextTestSetup } from 'e2e-utils' 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', () => { describe('app-dir - metadata-streaming-config-customized', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
overrideFiles: { overrideFiles: {
...@@ -19,8 +16,6 @@ describe('app-dir - metadata-streaming-config-customized', () => { ...@@ -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 () => { it('should have the customized streaming metadata config output in routes-manifest.json', async () => {
const prerenderManifest = JSON.parse( const prerenderManifest = JSON.parse(
await next.readFile('.next/prerender-manifest.json') await next.readFile('.next/prerender-manifest.json')
......
import { nextTestSetup } from 'e2e-utils' 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', () => { describe('app-dir - metadata-streaming-config', () => {
const { next, skipped } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true,
}) })
if (skipped) return
it('should have the default streaming metadata config output in routes-manifest.json', async () => { it('should have the default streaming metadata config output in routes-manifest.json', async () => {
const requiredServerFiles = JSON.parse( const requiredServerFiles = JSON.parse(
await next.readFile('.next/required-server-files.json') 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