Unverified Commit dc5dd46f authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] promote streaming metadata configs to stable (#76344)

parent 72e908d3
...@@ -2757,8 +2757,8 @@ export default async function build( ...@@ -2757,8 +2757,8 @@ export default async function build(
: undefined : undefined
const htmlBotsRegexString = const htmlBotsRegexString =
config.experimental.htmlLimitedBots || // The htmlLimitedBots has been converted to a string during loadConfig
HTML_LIMITED_BOT_UA_RE_STRING config.htmlLimitedBots || HTML_LIMITED_BOT_UA_RE_STRING
// this flag is used to selectively bypass the static cache and invoke the lambda directly // this flag is used to selectively bypass the static cache and invoke the lambda directly
// to enable server actions on static routes // to enable server actions on static routes
...@@ -2774,8 +2774,7 @@ export default async function build( ...@@ -2774,8 +2774,7 @@ export default async function build(
...(isRoutePPREnabled && ...(isRoutePPREnabled &&
// Disable streaming metadata for PPR on deployment where we don't have the special env. // 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. // TODO: enable streaming metadata in PPR mode by default once it's ready.
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' && process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
config.experimental.streamingMetadata
? [ ? [
{ {
type: 'header', type: 'header',
......
...@@ -380,6 +380,12 @@ async function exportAppImpl( ...@@ -380,6 +380,12 @@ async function exportAppImpl(
: {}), : {}),
strictNextHead: nextConfig.experimental.strictNextHead ?? true, strictNextHead: nextConfig.experimental.strictNextHead ?? true,
deploymentId: nextConfig.deploymentId, deploymentId: nextConfig.deploymentId,
htmlLimitedBots: nextConfig.htmlLimitedBots.source,
streamingMetadata:
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!nextConfig.experimental.dynamicIO,
experimental: { experimental: {
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata, clientTraceMetadata: nextConfig.experimental.clientTraceMetadata,
expireTime: nextConfig.expireTime, expireTime: nextConfig.expireTime,
...@@ -387,13 +393,6 @@ async function exportAppImpl( ...@@ -387,13 +393,6 @@ async function exportAppImpl(
clientSegmentCache: nextConfig.experimental.clientSegmentCache ?? false, clientSegmentCache: nextConfig.experimental.clientSegmentCache ?? false,
inlineCss: nextConfig.experimental.inlineCss ?? false, inlineCss: nextConfig.experimental.inlineCss ?? false,
authInterrupts: !!nextConfig.experimental.authInterrupts, authInterrupts: !!nextConfig.experimental.authInterrupts,
streamingMetadata:
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!nextConfig.experimental.dynamicIO &&
!!nextConfig.experimental.streamingMetadata,
htmlLimitedBots: nextConfig.experimental.htmlLimitedBots,
}, },
reactMaxHeadersLength: nextConfig.reactMaxHeadersLength, reactMaxHeadersLength: nextConfig.reactMaxHeadersLength,
} }
......
...@@ -429,8 +429,7 @@ export async function exportPages( ...@@ -429,8 +429,7 @@ export async function exportPages(
// Disable streaming metadata when dynamic IO is enabled. // Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case. // FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route // test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!nextConfig.experimental.dynamicIO && !nextConfig.experimental.dynamicIO,
!!nextConfig.experimental.streamingMetadata,
}), }),
// If exporting the page takes longer than the timeout, reject the promise. // If exporting the page takes longer than the timeout, reject the promise.
new Promise((_, reject) => { new Promise((_, reject) => {
......
...@@ -204,6 +204,8 @@ export interface RenderOptsPartial { ...@@ -204,6 +204,8 @@ export interface RenderOptsPartial {
} }
params?: ParsedUrlQuery params?: ParsedUrlQuery
isPrefetch?: boolean isPrefetch?: boolean
htmlLimitedBots: string | undefined
streamingMetadata: boolean
experimental: { experimental: {
/** /**
* When true, it indicates that the current page supports partial * When true, it indicates that the current page supports partial
...@@ -216,8 +218,6 @@ export interface RenderOptsPartial { ...@@ -216,8 +218,6 @@ export interface RenderOptsPartial {
clientSegmentCache: boolean clientSegmentCache: boolean
inlineCss: boolean inlineCss: boolean
authInterrupts: boolean authInterrupts: boolean
streamingMetadata: boolean
htmlLimitedBots: string | undefined
} }
postponed?: string postponed?: string
......
...@@ -602,6 +602,13 @@ export default abstract class Server< ...@@ -602,6 +602,13 @@ export default abstract class Server<
// @ts-expect-error internal field not publicly exposed // @ts-expect-error internal field not publicly exposed
isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile, isExperimentalCompile: this.nextConfig.experimental.isExperimentalCompile,
// `htmlLimitedBots` is passed to server as serialized config in string format
htmlLimitedBots: this.nextConfig.htmlLimitedBots,
streamingMetadata:
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!this.nextConfig.experimental.dynamicIO,
experimental: { experimental: {
expireTime: this.nextConfig.expireTime, expireTime: this.nextConfig.expireTime,
clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata, clientTraceMetadata: this.nextConfig.experimental.clientTraceMetadata,
...@@ -610,13 +617,6 @@ export default abstract class Server< ...@@ -610,13 +617,6 @@ export default abstract class Server<
this.nextConfig.experimental.clientSegmentCache ?? false, this.nextConfig.experimental.clientSegmentCache ?? false,
inlineCss: this.nextConfig.experimental.inlineCss ?? false, inlineCss: this.nextConfig.experimental.inlineCss ?? false,
authInterrupts: !!this.nextConfig.experimental.authInterrupts, authInterrupts: !!this.nextConfig.experimental.authInterrupts,
streamingMetadata:
// Disable streaming metadata when dynamic IO is enabled.
// FIXME: remove dynamic IO guard once we fixed the dynamic indicator case.
// test/e2e/app-dir/dynamic-io/dynamic-io.test.ts - should not have static indicator on not-found route
!this.nextConfig.experimental.dynamicIO &&
!!this.nextConfig.experimental.streamingMetadata,
htmlLimitedBots: this.nextConfig.experimental.htmlLimitedBots,
}, },
onInstrumentationRequestError: onInstrumentationRequestError:
this.instrumentationOnRequestError.bind(this), this.instrumentationOnRequestError.bind(this),
...@@ -1769,10 +1769,10 @@ export default abstract class Server< ...@@ -1769,10 +1769,10 @@ export default abstract class Server<
...this.renderOpts, ...this.renderOpts,
supportsDynamicResponse: !isBotRequest, supportsDynamicResponse: !isBotRequest,
botType: getBotType(ua), botType: getBotType(ua),
serveStreamingMetadata: shouldServeStreamingMetadata( serveStreamingMetadata: shouldServeStreamingMetadata(ua, {
ua, streamingMetadata: !!this.renderOpts.streamingMetadata,
this.renderOpts.experimental htmlLimitedBots: this.nextConfig.htmlLimitedBots,
), }),
}, },
} }
......
...@@ -448,8 +448,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -448,8 +448,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
typedEnv: z.boolean().optional(), typedEnv: z.boolean().optional(),
serverComponentsHmrCache: z.boolean().optional(), serverComponentsHmrCache: z.boolean().optional(),
authInterrupts: z.boolean().optional(), authInterrupts: z.boolean().optional(),
streamingMetadata: z.boolean().optional(),
htmlLimitedBots: z.instanceof(RegExp).optional(),
useCache: z.boolean().optional(), useCache: z.boolean().optional(),
slowModuleDetection: z slowModuleDetection: z
.object({ .object({
...@@ -489,6 +487,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -489,6 +487,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.args() .args()
.returns(z.promise(z.array(zHeader))) .returns(z.promise(z.array(zHeader)))
.optional(), .optional(),
htmlLimitedBots: z.instanceof(RegExp).optional(),
httpAgentOptions: z httpAgentOptions: z
.strictObject({ keepAlive: z.boolean().optional() }) .strictObject({ keepAlive: z.boolean().optional() })
.optional(), .optional(),
......
...@@ -23,9 +23,8 @@ export type NextConfigComplete = Required<NextConfig> & { ...@@ -23,9 +23,8 @@ export type NextConfigComplete = Required<NextConfig> & {
configFileName: string configFileName: string
// override NextConfigComplete.experimental.htmlLimitedBots to string // override NextConfigComplete.experimental.htmlLimitedBots to string
// because it's not defined in NextConfigComplete.experimental // because it's not defined in NextConfigComplete.experimental
experimental: Omit<ExperimentalConfig, 'htmlLimitedBots'> & { htmlLimitedBots: string | undefined
htmlLimitedBots: string | undefined experimental: ExperimentalConfig
}
} }
export type I18NDomains = readonly DomainLocale[] export type I18NDomains = readonly DomainLocale[]
...@@ -587,17 +586,6 @@ export interface ExperimentalConfig { ...@@ -587,17 +586,6 @@ export interface ExperimentalConfig {
*/ */
authInterrupts?: boolean authInterrupts?: boolean
/**
* When enabled will cause async metadata calls to stream rather than block the render.
*/
streamingMetadata?: boolean
/**
* User Agent of bots that can handle streaming metadata.
* Besides the default behavior, Next.js act differently on serving metadata to bots based on their capability.
*/
htmlLimitedBots?: RegExp
/** /**
* Enables the use of the `"use cache"` directive. * Enables the use of the `"use cache"` directive.
*/ */
...@@ -1079,6 +1067,12 @@ export interface NextConfig extends Record<string, any> { ...@@ -1079,6 +1067,12 @@ export interface NextConfig extends Record<string, any> {
watchOptions?: { watchOptions?: {
pollIntervalMs?: number pollIntervalMs?: number
} }
/**
* User agent of bots that should opt-out streaming metadata.
* User agents that pass this regex will block rendering until metadata has resolved, to ensure it's available in the `head` of the document.
*/
htmlLimitedBots?: RegExp
} }
export const defaultConfig: NextConfig = { export const defaultConfig: NextConfig = {
...@@ -1258,11 +1252,10 @@ export const defaultConfig: NextConfig = { ...@@ -1258,11 +1252,10 @@ export const defaultConfig: NextConfig = {
staticGenerationMinPagesPerWorker: 25, staticGenerationMinPagesPerWorker: 25,
dynamicIO: false, dynamicIO: false,
inlineCss: false, inlineCss: false,
streamingMetadata: true,
htmlLimitedBots: undefined,
useCache: undefined, useCache: undefined,
slowModuleDetection: undefined, slowModuleDetection: undefined,
}, },
htmlLimitedBots: undefined,
bundlePagesRouterDependencies: false, bundlePagesRouterDependencies: false,
} }
......
...@@ -1043,9 +1043,9 @@ function assignDefaults( ...@@ -1043,9 +1043,9 @@ function assignDefaults(
]), ]),
] ]
if (!result.experimental.htmlLimitedBots) { if (!result.htmlLimitedBots) {
// @ts-expect-error: override the htmlLimitedBots with default string, type covert: RegExp -> string // @ts-expect-error: override the htmlLimitedBots with default string, type covert: RegExp -> string
result.experimental.htmlLimitedBots = HTML_LIMITED_BOT_UA_RE_STRING result.htmlLimitedBots = HTML_LIMITED_BOT_UA_RE_STRING
} }
// "use cache" was originally implicitly enabled with the dynamicIO flag, so // "use cache" was originally implicitly enabled with the dynamicIO flag, so
...@@ -1169,10 +1169,10 @@ export default async function loadConfig( ...@@ -1169,10 +1169,10 @@ export default async function loadConfig(
throw err throw err
} }
const userConfig = await normalizeConfig( const userConfig = (await normalizeConfig(
phase, phase,
userConfigModule.default || userConfigModule userConfigModule.default || userConfigModule
) )) as NextConfig
if (!process.env.NEXT_MINIMAL) { if (!process.env.NEXT_MINIMAL) {
// We only validate the config against schema in non minimal mode // We only validate the config against schema in non minimal mode
...@@ -1221,7 +1221,7 @@ export default async function loadConfig( ...@@ -1221,7 +1221,7 @@ export default async function loadConfig(
const { canonicalBase } = userConfig.amp || ({} as any) const { canonicalBase } = userConfig.amp || ({} as any)
userConfig.amp = userConfig.amp || {} userConfig.amp = userConfig.amp || {}
userConfig.amp.canonicalBase = userConfig.amp.canonicalBase =
(canonicalBase.endsWith('/') (canonicalBase?.endsWith('/')
? canonicalBase.slice(0, -1) ? canonicalBase.slice(0, -1)
: canonicalBase) || '' : canonicalBase) || ''
} }
...@@ -1264,9 +1264,9 @@ export default async function loadConfig( ...@@ -1264,9 +1264,9 @@ export default async function loadConfig(
} }
// serialize the regex config into string // serialize the regex config into string
if (userConfig.experimental?.htmlLimitedBots instanceof RegExp) { if (userConfig?.htmlLimitedBots instanceof RegExp) {
userConfig.experimental.htmlLimitedBots = // @ts-expect-error: override the htmlLimitedBots with default string, type covert: RegExp -> string
userConfig.experimental.htmlLimitedBots.source userConfig.htmlLimitedBots = userConfig.htmlLimitedBots.source
} }
onLoadUserConfig?.(userConfig) onLoadUserConfig?.(userConfig)
......
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {}
experimental: {
streamingMetadata: true,
},
}
module.exports = nextConfig module.exports = nextConfig
...@@ -6,10 +6,7 @@ describe('app-dir - metadata-streaming-customized-rule', () => { ...@@ -6,10 +6,7 @@ describe('app-dir - metadata-streaming-customized-rule', () => {
overrideFiles: { overrideFiles: {
'next.config.js': ` 'next.config.js': `
module.exports = { module.exports = {
experimental: { htmlLimitedBots: /Minibot/i,
streamingMetadata: true,
htmlLimitedBots: /Minibot/i,
}
} }
`, `,
}, },
......
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {}
experimental: {
streamingMetadata: true,
},
}
module.exports = nextConfig module.exports = nextConfig
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: true, ppr: true,
streamingMetadata: true,
}, },
} }
......
...@@ -10,10 +10,9 @@ describe('app-dir - metadata-streaming-config-customized', () => { ...@@ -10,10 +10,9 @@ describe('app-dir - metadata-streaming-config-customized', () => {
overrideFiles: { overrideFiles: {
'next.config.js': ` 'next.config.js': `
module.exports = { module.exports = {
experimental: { htmlLimitedBots: /MyBot/i,
experimental: {
ppr: 'incremental', ppr: 'incremental',
streamingMetadata: true,
htmlLimitedBots: /MyBot/i,
} }
} }
`, `,
......
...@@ -16,9 +16,7 @@ describe('app-dir - metadata-streaming-config', () => { ...@@ -16,9 +16,7 @@ describe('app-dir - metadata-streaming-config', () => {
await next.readFile('.next/required-server-files.json') await next.readFile('.next/required-server-files.json')
) )
expect( expect(requiredServerFiles.config.htmlLimitedBots).toMatchInlineSnapshot(
requiredServerFiles.config.experimental.htmlLimitedBots
).toMatchInlineSnapshot(
`"Mediapartners-Google|Slurp|DuckDuckBot|baiduspider|yandex|sogou|bitlybot|tumblr|vkShare|quora link preview|redditbot|ia_archiver|Bingbot|BingPreview|applebot|facebookexternalhit|facebookcatalog|Twitterbot|LinkedInBot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview"` `"Mediapartners-Google|Slurp|DuckDuckBot|baiduspider|yandex|sogou|bitlybot|tumblr|vkShare|quora link preview|redditbot|ia_archiver|Bingbot|BingPreview|applebot|facebookexternalhit|facebookcatalog|Twitterbot|LinkedInBot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview"`
) )
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: 'incremental', ppr: 'incremental',
streamingMetadata: true,
}, },
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
ppr: 'incremental', ppr: 'incremental',
streamingMetadata: true,
}, },
} }
......
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