Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metadata] add option of configuring ua of async metadata #74594

Merged
merged 13 commits into from
Jan 10, 2025

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Jan 7, 2025

What

Introduce an experimental config experimental.htmlLimitedBots (type Regex) which can used for controlling the metadata streaming behavior for different bots, if the bots user agent is matching the regex, it will serve blocking metadata forcedly. This gives users some control to opt-out streaming metadata for some clients or bots which cannot handle it.

Output another manifest response-config-manfiest.json containing the customized UA, which is potentially used for the platform serving Next.js to control the returned response for certain UA. But it's mostly for PPR case which we'll tackle later.

Closes NDX-635
Closes NDX-599

Copy link
Member Author

huozhi commented Jan 7, 2025

@ijjk
Copy link
Member

ijjk commented Jan 7, 2025

Failing test suites

Commit: 64914df

pnpm test-dev-turbo test/development/acceptance-app/ReactRefreshRequire.test.ts (turbopack)

  • ReactRefreshRequire app > propagates a hot update to closest accepted module
Expand output

● ReactRefreshRequire app › propagates a hot update to closest accepted module

expect(received).toEqual(expected) // deep equality

- Expected  - 0
+ Received  + 1

  Array [
    "init FooV1",
+   "init FooV1",
    "init BarV3",
  ]

  142 |       `
  143 |     )
> 144 |     expect(await session.evaluate(() => (window as any).log)).toEqual([
      |                                                               ^
  145 |       // // FIXME: Metro order:
  146 |       // 'init BarV3',
  147 |       // 'init FooV1',

  at Object.toEqual (development/acceptance-app/ReactRefreshRequire.test.ts:144:63)

Read more about building and testing Next.js in contributing.md.

@ijjk
Copy link
Member

ijjk commented Jan 7, 2025

Stats from current PR

Default Build (Increase detected ⚠️)
General
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
buildDuration 36.4s 34.1s N/A
buildDurationCached 29.2s 24.7s N/A
nodeModulesSize 417 MB 417 MB N/A
nextStartRea..uration (ms) 949ms 775ms N/A
Client Bundles (main, webpack)
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
5306-HASH.js gzip 53.3 kB 53.4 kB N/A
8276.HASH.js gzip 169 B 168 B N/A
8377-HASH.js gzip 5.44 kB 5.44 kB N/A
bccd1874-HASH.js gzip 53 kB 53 kB
framework-HASH.js gzip 57.5 kB 57.5 kB N/A
main-app-HASH.js gzip 240 B 242 B N/A
main-HASH.js gzip 34.1 kB 34.2 kB N/A
webpack-HASH.js gzip 1.71 kB 1.71 kB N/A
Overall change 53 kB 53 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Overall change 39.4 kB 39.4 kB
Client Pages
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 193 B 193 B
amp-HASH.js gzip 512 B 510 B N/A
css-HASH.js gzip 343 B 342 B N/A
dynamic-HASH.js gzip 1.84 kB 1.84 kB
edge-ssr-HASH.js gzip 265 B 265 B
head-HASH.js gzip 363 B 362 B N/A
hooks-HASH.js gzip 393 B 392 B N/A
image-HASH.js gzip 4.57 kB 4.57 kB N/A
index-HASH.js gzip 268 B 268 B
link-HASH.js gzip 2.35 kB 2.34 kB N/A
routerDirect..HASH.js gzip 328 B 328 B
script-HASH.js gzip 397 B 397 B
withRouter-HASH.js gzip 323 B 326 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 3.59 kB 3.59 kB
Client Build Manifests
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
_buildManifest.js gzip 749 B 747 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
index.html gzip 522 B 523 B N/A
link.html gzip 538 B 537 B N/A
withRouter.html gzip 518 B 520 B N/A
Overall change 0 B 0 B
Edge SSR bundle Size Overall increase ⚠️
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
edge-ssr.js gzip 128 kB 129 kB ⚠️ +212 B
page.js gzip 207 kB 207 kB ⚠️ +140 B
Overall change 335 kB 336 kB ⚠️ +352 B
Middleware size
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
middleware-b..fest.js gzip 671 B 670 B N/A
middleware-r..fest.js gzip 155 B 156 B N/A
middleware.js gzip 31.2 kB 31.2 kB N/A
edge-runtime..pack.js gzip 844 B 844 B
Overall change 844 B 844 B
Next Runtimes
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
274-experime...dev.js gzip 322 B 322 B
274.runtime.dev.js gzip 314 B 314 B
app-page-exp...dev.js gzip 369 kB 368 kB N/A
app-page-exp..prod.js gzip 130 kB 130 kB N/A
app-page-tur..prod.js gzip 142 kB 142 kB N/A
app-page-tur..prod.js gzip 138 kB 138 kB
app-page.run...dev.js gzip 357 kB 355 kB N/A
app-page.run..prod.js gzip 126 kB 126 kB
app-route-ex...dev.js gzip 37.6 kB 37.6 kB
app-route-ex..prod.js gzip 25.6 kB 25.6 kB
app-route-tu..prod.js gzip 25.6 kB 25.6 kB
app-route-tu..prod.js gzip 25.4 kB 25.4 kB
app-route.ru...dev.js gzip 39.2 kB 39.2 kB
app-route.ru..prod.js gzip 25.4 kB 25.4 kB
pages-api-tu..prod.js gzip 9.69 kB 9.69 kB
pages-api.ru...dev.js gzip 11.6 kB 11.6 kB
pages-api.ru..prod.js gzip 9.68 kB 9.68 kB
pages-turbo...prod.js gzip 21.7 kB 21.7 kB N/A
pages.runtim...dev.js gzip 27.5 kB 27.5 kB N/A
pages.runtim..prod.js gzip 21.7 kB 21.7 kB N/A
server.runti..prod.js gzip 916 kB 916 kB N/A
Overall change 474 kB 474 kB
build cache
vercel/next.js canary vercel/next.js huozhi/01-07-streaming_metadata_config Change
0.pack gzip 2.1 MB 2.09 MB N/A
index.pack gzip 75.7 kB 75.5 kB N/A
Overall change 0 B 0 B
Diff details
Diff for page.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for 5306-HASH.js

Diff too large to display

Diff for main-HASH.js

Diff too large to display

Diff for app-page-exp..ntime.dev.js
failed to diff
Diff for app-page-exp..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page.runtime.dev.js
failed to diff
Diff for app-page.runtime.prod.js

Diff too large to display

Diff for pages-turbo...time.prod.js

Diff too large to display

Diff for pages.runtime.dev.js
@@ -31,7 +31,7 @@ To revalidate as soon as possible, you can set the value to \`1\`.`),"__NEXT_ERR
 To only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`),revalidate=data.revalidate}else throw Object.defineProperty(Error(`A page's revalidate option must be seconds expressed as a natural number for ${req.url}. Mixed numbers, such as '${data.revalidate}', cannot be used.
 Try changing the value to '${Math.ceil(data.revalidate)}' or using \`Math.ceil()\` if you're computing the value.`),"__NEXT_ERROR_CODE",{value:"E438",enumerable:!1})}else if(!0===data.revalidate)revalidate=1;else if(!1===data.revalidate||void 0===data.revalidate)revalidate=!1;else throw Object.defineProperty(Error(`A page's revalidate option must be seconds expressed as a natural number. Mixed numbers and strings cannot be used. Received '${JSON.stringify(data.revalidate)}' for ${req.url}`),"__NEXT_ERROR_CODE",{value:"E161",enumerable:!1})}else revalidate=!1;if(props.pageProps=Object.assign({},props.pageProps,"props"in data?data.props:void 0),metadata.revalidate=revalidate,metadata.pageData=props,metadata.isNotFound)return new RenderResult(null,{metadata})}if(getServerSideProps&&(props.__N_SSP=!0),getServerSideProps&&!isFallback){let data;let canAccessRes=!0,resOrProxy=res,deferredContent=!1;resOrProxy=new Proxy(res,{get:function(obj,prop){if(!canAccessRes){let message=`You should not access 'res' after getServerSideProps resolves.
 Read more: https://nextjs.org/docs/messages/gssp-no-mutating-res`;if(deferredContent)throw Object.defineProperty(Error(message),"__NEXT_ERROR_CODE",{value:"E394",enumerable:!1});warn(message)}return reflect.l.get(obj,prop,res)}});try{data=await (0,tracer_.getTracer)().trace(trace_constants.vr.getServerSideProps,{spanName:`getServerSideProps ${pathname}`,attributes:{"next.route":pathname}},async()=>getServerSideProps({req:req,res:resOrProxy,query,resolvedUrl:renderOpts.resolvedUrl,...pageIsDynamic?{params}:void 0,...!1!==previewData?{draftMode:!0,preview:!0,previewData:previewData}:void 0,locales:[...renderOpts.locales??[]],locale:renderOpts.locale,defaultLocale:renderOpts.defaultLocale})),canAccessRes=!1,metadata.revalidate=0}catch(serverSidePropsError){throw"object"==typeof serverSidePropsError&&null!==serverSidePropsError&&"name"in serverSidePropsError&&"message"in serverSidePropsError&&"ENOENT"===serverSidePropsError.code&&delete serverSidePropsError.code,serverSidePropsError}if(null==data)throw Object.defineProperty(Error(constants.UO),"__NEXT_ERROR_CODE",{value:"E394",enumerable:!1});data.props instanceof Promise&&(deferredContent=!0);let invalidKeys=Object.keys(data).filter(key=>"props"!==key&&"redirect"!==key&&"notFound"!==key);if(data.unstable_notFound)throw Object.defineProperty(Error(`unstable_notFound has been renamed to notFound, please update the field to continue. Page: ${pathname}`),"__NEXT_ERROR_CODE",{value:"E516",enumerable:!1});if(data.unstable_redirect)throw Object.defineProperty(Error(`unstable_redirect has been renamed to redirect, please update the field to continue. Page: ${pathname}`),"__NEXT_ERROR_CODE",{value:"E284",enumerable:!1});if(invalidKeys.length)throw Object.defineProperty(Error(invalidKeysMsg("getServerSideProps",invalidKeys)),"__NEXT_ERROR_CODE",{value:"E394",enumerable:!1});if("notFound"in data&&data.notFound){if("/404"===pathname)throw Object.defineProperty(Error('The /404 page can not return notFound in "getStaticProps", please remove it to continue!'),"__NEXT_ERROR_CODE",{value:"E121",enumerable:!1});return metadata.isNotFound=!0,new RenderResult(null,{metadata})}if("redirect"in data&&"object"==typeof data.redirect&&(checkRedirectValues(data.redirect,req,"getServerSideProps"),data.props={__N_REDIRECT:data.redirect.destination,__N_REDIRECT_STATUS:getRedirectStatus(data.redirect)},void 0!==data.redirect.basePath&&(data.props.__N_REDIRECT_BASE_PATH=data.redirect.basePath),metadata.isRedirect=!0),deferredContent&&(data.props=await data.props),(dev||isBuildTimeSSG)&&!isSerializableProps(pathname,"getServerSideProps",data.props))throw Object.defineProperty(Error("invariant: getServerSideProps did not return valid props. Please report this."),"__NEXT_ERROR_CODE",{value:"E31",enumerable:!1});props.pageProps=Object.assign({},props.pageProps,data.props),metadata.pageData=props}if(!isSSG&&!getServerSideProps&&Object.keys((null==props?void 0:props.pageProps)||{}).includes("url")&&console.warn(`The prop \`url\` is a reserved prop in Next.js for legacy reasons and will be overridden on page ${pathname}
-See more info here: https://nextjs.org/docs/messages/reserved-page-prop`),isNextDataRequest&&!isSSG||metadata.isRedirect)return new RenderResult(JSON.stringify(props),{metadata});if(isFallback&&(props.pageProps={}),isResSent(res)&&!isSSG)return new RenderResult(null,{metadata});let filteredBuildManifest=buildManifest;if(isAutoExport&&pageIsDynamic){let _page;let page=(_page=(function(page){let normalized=/^\/index(\/|$)/.test(page)&&!isDynamicRoute(page)?"/index"+page:"/"===page?"/index":ensureLeadingSlash(page);{let{posix}=__webpack_require__("path"),resolvedPage=posix.normalize(normalized);if(resolvedPage!==normalized)throw new NormalizeError("Requested and resolved page mismatch: "+normalized+" "+resolvedPage)}return normalized})(pathname).replace(/\\/g,"/")).startsWith("/index/")&&!isDynamicRoute(_page)?_page.slice(6):"/index"!==_page?_page:"/";page in filteredBuildManifest.pages&&(filteredBuildManifest={...filteredBuildManifest,pages:{...filteredBuildManifest.pages,[page]:[...filteredBuildManifest.pages[page],...filteredBuildManifest.lowPriorityFiles.filter(f=>f.includes("_buildManifest"))]},lowPriorityFiles:filteredBuildManifest.lowPriorityFiles.filter(f=>!f.includes("_buildManifest"))})}let Body=({children})=>inAmpMode?children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)("div",{id:"__next",children:children}),renderDocument=async()=>{let documentInitialPropsRes,styles;async function loadDocumentInitialProps(renderShell){let renderPage=async(options={})=>{if(ctx.err&&ErrorDebug)return renderShell&&renderShell(App,Component),{html:await renderToString(/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(ErrorDebug,{})})),head};if(dev&&(props.router||props.Component))throw Object.defineProperty(Error("'router' and 'Component' can not be returned in getInitialProps from _app.js https://nextjs.org/docs/messages/cant-override-next-props"),"__NEXT_ERROR_CODE",{value:"E230",enumerable:!1});let{App:EnhancedApp,Component:EnhancedComponent}="function"==typeof options?{App:App,Component:options(Component)}:{App:options.enhanceApp?options.enhanceApp(App):App,Component:options.enhanceComponent?options.enhanceComponent(Component):Component},stream=await renderShell(EnhancedApp,EnhancedComponent);return await stream.allReady,{html:await streamToString(stream),head}},documentCtx={...ctx,renderPage},docProps=await loadGetInitialProps(Document,documentCtx);if(isResSent(res)&&!isSSG)return null;if(!docProps||"string"!=typeof docProps.html)throw Object.defineProperty(Error(`"${getDisplayName(Document)}.getInitialProps()" should resolve to an object with a "html" prop set with a valid html string`),"__NEXT_ERROR_CODE",{value:"E394",enumerable:!1});return{docProps,documentCtx}}Document.__NEXT_BUILTIN_DOCUMENT__;let renderContent=(_App,_Component)=>{let EnhancedApp=_App||App,EnhancedComponent=_Component||Component;return ctx.err&&ErrorDebug?/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(ErrorDebug,{})}):/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(AppContainerWithIsomorphicFiberStructure,{children:renderPageTree(EnhancedApp,EnhancedComponent,{...props,router})})})},renderShell=async(EnhancedApp,EnhancedComponent)=>{let content=renderContent(EnhancedApp,EnhancedComponent);return await function({ReactDOMServer,element,streamOptions}){return(0,tracer_.getTracer)().trace(trace_constants.Wc.renderToReadableStream,async()=>ReactDOMServer.renderToReadableStream(element,streamOptions))}({ReactDOMServer:ReactDOMServerPages_default(),element:content})},hasDocumentGetInitialProps=!!Document.getInitialProps,[rawStyledJsxInsertedHTML,content]=await Promise.all([renderToString(styledJsxInsertedHTML()),(async()=>{if(hasDocumentGetInitialProps){if(null===(documentInitialPropsRes=await loadDocumentInitialProps(renderShell)))return null;let{docProps}=documentInitialPropsRes;return docProps.html}{documentInitialPropsRes={};let stream=await renderShell(App,Component);return await stream.allReady,streamToString(stream)}})()]);if(null===content)return null;let{docProps}=documentInitialPropsRes||{};return hasDocumentGetInitialProps?(styles=docProps.styles,head=docProps.head):(styles=jsxStyleRegistry.styles(),jsxStyleRegistry.flush()),{contentHTML:rawStyledJsxInsertedHTML+content,documentElement:htmlProps=>/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Document,{...htmlProps,...docProps}),head,headTags:[],styles}};(0,tracer_.getTracer)().setRootSpanAttribute("next.route",renderOpts.page);let documentResult=await (0,tracer_.getTracer)().trace(trace_constants.vr.renderDocument,{spanName:`render route (pages) ${renderOpts.page}`,attributes:{"next.route":renderOpts.page}},async()=>renderDocument());if(!documentResult)return new RenderResult(null,{metadata});let dynamicImportsIds=new Set,dynamicImports=new Set;for(let mod of reactLoadableModules){let manifestItem=reactLoadableManifest[mod];manifestItem&&(dynamicImportsIds.add(manifestItem.id),manifestItem.files.forEach(item=>{dynamicImports.add(item)}))}let hybridAmp=ampState.hybrid,docComponentsRendered={},{assetPrefix,defaultLocale,disableOptimizedLoading,domainLocales,locale,locales,runtimeConfig}=renderOpts,htmlProps={__NEXT_DATA__:{props,page:pathname,query,buildId:sharedContext.buildId,assetPrefix:""===assetPrefix?void 0:assetPrefix,runtimeConfig,nextExport:!0===nextExport||void 0,autoExport:!0===isAutoExport||void 0,isFallback,isExperimentalCompile,dynamicIds:0===dynamicImportsIds.size?void 0:Array.from(dynamicImportsIds),err:renderOpts.err?(err=renderOpts.err,dev?(source="server",source=err[symbolError]||"server",{name:err.name,source,message:strip_ansi_default()(err.message),stack:err.stack,digest:err.digest}):{name:"Internal Server Error.",message:"500 - Internal Server Error.",statusCode:500}):void 0,gsp:!!getStaticProps||void 0,gssp:!!getServerSideProps||void 0,customServer:sharedContext.customServer,gip:!!hasPageGetInitialProps||void 0,appGip:!defaultAppGetInitialProps||void 0,locale,locales,defaultLocale,domainLocales,isPreview:!0===isPreview||void 0,notFoundSrcPage:notFoundSrcPage&&dev?notFoundSrcPage:void 0},strictNextHead:renderOpts.strictNextHead,buildManifest:filteredBuildManifest,docComponentsRendered,dangerousAsPath:router.asPath,canonicalBase:!renderOpts.ampPath&&request_meta_getRequestMeta(req,"didStripLocale")?`${renderOpts.canonicalBase||""}/${renderOpts.locale}`:renderOpts.canonicalBase,ampPath,inAmpMode,isDevelopment:!!dev,hybridAmp,dynamicImports:Array.from(dynamicImports),dynamicCssManifest:new Set(renderOpts.dynamicCssManifest||[]),assetPrefix,unstable_runtimeJS:void 0,unstable_JsPreload:pageConfig.unstable_JsPreload,assetQueryString,scriptLoader,locale,disableOptimizedLoading,head:documentResult.head,headTags:documentResult.headTags,styles:documentResult.styles,crossOrigin:renderOpts.crossOrigin,optimizeCss:renderOpts.optimizeCss,nextConfigOutput:renderOpts.nextConfigOutput,nextScriptWorkers:renderOpts.nextScriptWorkers,runtime:globalRuntime,largePageDataBytes:renderOpts.largePageDataBytes,nextFontManifest:renderOpts.nextFontManifest,experimentalClientTraceMetadata:renderOpts.experimental.clientTraceMetadata},document=/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(amp_context_shared_runtime_AmpStateContext.Provider,{value:ampState,children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(HtmlContext.Provider,{value:htmlProps,children:documentResult.documentElement(htmlProps)})}),documentHTML=await (0,tracer_.getTracer)().trace(trace_constants.vr.renderToString,async()=>renderToString(document));{let nonRenderedComponents=[];for(let comp of["Main","Head","NextScript","Html"])docComponentsRendered[comp]||nonRenderedComponents.push(comp);if(nonRenderedComponents.length){let missingComponentList=nonRenderedComponents.map(e=>`<${e} />`).join(", "),plural=1!==nonRenderedComponents.length?"s":"";console.warn(`Your custom Document (pages/_document) did not render all the required subcomponent${plural}.
+See more info here: https://nextjs.org/docs/messages/reserved-page-prop`),isNextDataRequest&&!isSSG||metadata.isRedirect)return new RenderResult(JSON.stringify(props),{metadata});if(isFallback&&(props.pageProps={}),isResSent(res)&&!isSSG)return new RenderResult(null,{metadata});let filteredBuildManifest=buildManifest;if(isAutoExport&&pageIsDynamic){let _page;let page=(_page=(function(page){let normalized=/^\/index(\/|$)/.test(page)&&!isDynamicRoute(page)?"/index"+page:"/"===page?"/index":ensureLeadingSlash(page);{let{posix}=__webpack_require__("path"),resolvedPage=posix.normalize(normalized);if(resolvedPage!==normalized)throw new NormalizeError("Requested and resolved page mismatch: "+normalized+" "+resolvedPage)}return normalized})(pathname).replace(/\\/g,"/")).startsWith("/index/")&&!isDynamicRoute(_page)?_page.slice(6):"/index"!==_page?_page:"/";page in filteredBuildManifest.pages&&(filteredBuildManifest={...filteredBuildManifest,pages:{...filteredBuildManifest.pages,[page]:[...filteredBuildManifest.pages[page],...filteredBuildManifest.lowPriorityFiles.filter(f=>f.includes("_buildManifest"))]},lowPriorityFiles:filteredBuildManifest.lowPriorityFiles.filter(f=>!f.includes("_buildManifest"))})}let Body=({children})=>inAmpMode?children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)("div",{id:"__next",children:children}),renderDocument=async()=>{let documentInitialPropsRes,styles;async function loadDocumentInitialProps(renderShell){let renderPage=async(options={})=>{if(ctx.err&&ErrorDebug)return renderShell&&renderShell(App,Component),{html:await renderToString(/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(ErrorDebug,{error:ctx.err})})),head};if(dev&&(props.router||props.Component))throw Object.defineProperty(Error("'router' and 'Component' can not be returned in getInitialProps from _app.js https://nextjs.org/docs/messages/cant-override-next-props"),"__NEXT_ERROR_CODE",{value:"E230",enumerable:!1});let{App:EnhancedApp,Component:EnhancedComponent}="function"==typeof options?{App:App,Component:options(Component)}:{App:options.enhanceApp?options.enhanceApp(App):App,Component:options.enhanceComponent?options.enhanceComponent(Component):Component},stream=await renderShell(EnhancedApp,EnhancedComponent);return await stream.allReady,{html:await streamToString(stream),head}},documentCtx={...ctx,renderPage},docProps=await loadGetInitialProps(Document,documentCtx);if(isResSent(res)&&!isSSG)return null;if(!docProps||"string"!=typeof docProps.html)throw Object.defineProperty(Error(`"${getDisplayName(Document)}.getInitialProps()" should resolve to an object with a "html" prop set with a valid html string`),"__NEXT_ERROR_CODE",{value:"E394",enumerable:!1});return{docProps,documentCtx}}Document.__NEXT_BUILTIN_DOCUMENT__;let renderContent=(_App,_Component)=>{let EnhancedApp=_App||App,EnhancedComponent=_Component||Component;return ctx.err&&ErrorDebug?/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(ErrorDebug,{error:ctx.err})}):/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Body,{children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(AppContainerWithIsomorphicFiberStructure,{children:renderPageTree(EnhancedApp,EnhancedComponent,{...props,router})})})},renderShell=async(EnhancedApp,EnhancedComponent)=>{let content=renderContent(EnhancedApp,EnhancedComponent);return await function({ReactDOMServer,element,streamOptions}){return(0,tracer_.getTracer)().trace(trace_constants.Wc.renderToReadableStream,async()=>ReactDOMServer.renderToReadableStream(element,streamOptions))}({ReactDOMServer:ReactDOMServerPages_default(),element:content})},hasDocumentGetInitialProps=!!Document.getInitialProps,[rawStyledJsxInsertedHTML,content]=await Promise.all([renderToString(styledJsxInsertedHTML()),(async()=>{if(hasDocumentGetInitialProps){if(null===(documentInitialPropsRes=await loadDocumentInitialProps(renderShell)))return null;let{docProps}=documentInitialPropsRes;return docProps.html}{documentInitialPropsRes={};let stream=await renderShell(App,Component);return await stream.allReady,streamToString(stream)}})()]);if(null===content)return null;let{docProps}=documentInitialPropsRes||{};return hasDocumentGetInitialProps?(styles=docProps.styles,head=docProps.head):(styles=jsxStyleRegistry.styles(),jsxStyleRegistry.flush()),{contentHTML:rawStyledJsxInsertedHTML+content,documentElement:htmlProps=>/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(Document,{...htmlProps,...docProps}),head,headTags:[],styles}};(0,tracer_.getTracer)().setRootSpanAttribute("next.route",renderOpts.page);let documentResult=await (0,tracer_.getTracer)().trace(trace_constants.vr.renderDocument,{spanName:`render route (pages) ${renderOpts.page}`,attributes:{"next.route":renderOpts.page}},async()=>renderDocument());if(!documentResult)return new RenderResult(null,{metadata});let dynamicImportsIds=new Set,dynamicImports=new Set;for(let mod of reactLoadableModules){let manifestItem=reactLoadableManifest[mod];manifestItem&&(dynamicImportsIds.add(manifestItem.id),manifestItem.files.forEach(item=>{dynamicImports.add(item)}))}let hybridAmp=ampState.hybrid,docComponentsRendered={},{assetPrefix,defaultLocale,disableOptimizedLoading,domainLocales,locale,locales,runtimeConfig}=renderOpts,htmlProps={__NEXT_DATA__:{props,page:pathname,query,buildId:sharedContext.buildId,assetPrefix:""===assetPrefix?void 0:assetPrefix,runtimeConfig,nextExport:!0===nextExport||void 0,autoExport:!0===isAutoExport||void 0,isFallback,isExperimentalCompile,dynamicIds:0===dynamicImportsIds.size?void 0:Array.from(dynamicImportsIds),err:renderOpts.err?(err=renderOpts.err,dev?(source="server",source=err[symbolError]||"server",{name:err.name,source,message:strip_ansi_default()(err.message),stack:err.stack,digest:err.digest}):{name:"Internal Server Error.",message:"500 - Internal Server Error.",statusCode:500}):void 0,gsp:!!getStaticProps||void 0,gssp:!!getServerSideProps||void 0,customServer:sharedContext.customServer,gip:!!hasPageGetInitialProps||void 0,appGip:!defaultAppGetInitialProps||void 0,locale,locales,defaultLocale,domainLocales,isPreview:!0===isPreview||void 0,notFoundSrcPage:notFoundSrcPage&&dev?notFoundSrcPage:void 0},strictNextHead:renderOpts.strictNextHead,buildManifest:filteredBuildManifest,docComponentsRendered,dangerousAsPath:router.asPath,canonicalBase:!renderOpts.ampPath&&request_meta_getRequestMeta(req,"didStripLocale")?`${renderOpts.canonicalBase||""}/${renderOpts.locale}`:renderOpts.canonicalBase,ampPath,inAmpMode,isDevelopment:!!dev,hybridAmp,dynamicImports:Array.from(dynamicImports),dynamicCssManifest:new Set(renderOpts.dynamicCssManifest||[]),assetPrefix,unstable_runtimeJS:void 0,unstable_JsPreload:pageConfig.unstable_JsPreload,assetQueryString,scriptLoader,locale,disableOptimizedLoading,head:documentResult.head,headTags:documentResult.headTags,styles:documentResult.styles,crossOrigin:renderOpts.crossOrigin,optimizeCss:renderOpts.optimizeCss,nextConfigOutput:renderOpts.nextConfigOutput,nextScriptWorkers:renderOpts.nextScriptWorkers,runtime:globalRuntime,largePageDataBytes:renderOpts.largePageDataBytes,nextFontManifest:renderOpts.nextFontManifest,experimentalClientTraceMetadata:renderOpts.experimental.clientTraceMetadata},document=/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(amp_context_shared_runtime_AmpStateContext.Provider,{value:ampState,children:/*#__PURE__*/(0,jsx_runtime_namespaceObject.jsx)(HtmlContext.Provider,{value:htmlProps,children:documentResult.documentElement(htmlProps)})}),documentHTML=await (0,tracer_.getTracer)().trace(trace_constants.vr.renderToString,async()=>renderToString(document));{let nonRenderedComponents=[];for(let comp of["Main","Head","NextScript","Html"])docComponentsRendered[comp]||nonRenderedComponents.push(comp);if(nonRenderedComponents.length){let missingComponentList=nonRenderedComponents.map(e=>`<${e} />`).join(", "),plural=1!==nonRenderedComponents.length?"s":"";console.warn(`Your custom Document (pages/_document) did not render all the required subcomponent${plural}.
 Missing component${plural}: ${missingComponentList}
 Read how to fix here: https://nextjs.org/docs/messages/missing-document-component`)}}let[renderTargetPrefix,renderTargetSuffix]=documentHTML.split("<next-js-internal-body-render-target></next-js-internal-body-render-target>",2),prefix="";documentHTML.startsWith(DOCTYPE)||(prefix+=DOCTYPE),prefix+=renderTargetPrefix,inAmpMode&&(prefix+="\x3c!-- __NEXT_DATA__ --\x3e");let content=prefix+documentResult.contentHTML+renderTargetSuffix;return new RenderResult(await postProcessHTML(pathname,content,renderOpts,{inAmpMode,hybridAmp}),{metadata})}let renderToHTML=(req,res,pathname,query,renderOpts,sharedContext,renderContext)=>renderToHTMLImpl(req,res,pathname,query,renderOpts,renderOpts,sharedContext,renderContext),ServerInsertedHTMLContext=/*#__PURE__*/external_react_default().createContext(null);function useServerInsertedHTML(callback){let addInsertedServerHTMLCallback=(0,external_react_namespaceObject.useContext)(ServerInsertedHTMLContext);addInsertedServerHTMLCallback&&addInsertedServerHTMLCallback(callback)}class PagesRouteModule extends RouteModule{constructor(options){super(options),this.components=options.components}render(req,res,context){return renderToHTMLImpl(req,res,context.page,context.query,context.renderOpts,{App:this.components.App,Document:this.components.Document},context.sharedContext,context.renderContext)}}let vendored={contexts:entrypoints_namespaceObject},pages_module=PagesRouteModule})(),module.exports=__webpack_exports__})();
 //# sourceMappingURL=pages.runtime.dev.js.map
\ No newline at end of file
Diff for pages.runtime.prod.js

Diff too large to display

Diff for server.runtime.prod.js

Diff too large to display

Commit: 64914df

Base automatically changed from 12-25-replace_array_head_to_react_node to canary January 7, 2025 15:00
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch 2 times, most recently from 53858bb to 60d8738 Compare January 7, 2025 22:47
@huozhi huozhi changed the base branch from canary to huozhi/01-07-wrap_metadata_with_suspense_boundary January 7, 2025 22:47
@huozhi huozhi force-pushed the huozhi/01-07-wrap_metadata_with_suspense_boundary branch from f1c49dc to 6298a3b Compare January 8, 2025 22:25
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch from 60d8738 to 8b4da40 Compare January 8, 2025 22:26
@huozhi huozhi force-pushed the huozhi/01-07-wrap_metadata_with_suspense_boundary branch from 6298a3b to 0295e82 Compare January 8, 2025 23:25
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch from 8b4da40 to cab8c4d Compare January 8, 2025 23:47
@huozhi huozhi force-pushed the huozhi/01-07-wrap_metadata_with_suspense_boundary branch from e546a4f to c8aa61f Compare January 9, 2025 00:27
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch from cab8c4d to ede3e54 Compare January 9, 2025 00:27
@huozhi huozhi marked this pull request as ready for review January 9, 2025 00:31
@huozhi huozhi requested a review from ztanner January 9, 2025 00:31
Base automatically changed from huozhi/01-07-wrap_metadata_with_suspense_boundary to canary January 9, 2025 10:04
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch 2 times, most recently from bd55ee5 to cc3e8a5 Compare January 9, 2025 10:26
Copy link

vercel bot commented Jan 9, 2025

Notifying the following users due to files changed in this PR based on this repo's notify modifiers:

@timneutkens, @ijjk, @shuding:

packages/next/src/server/config.ts

@huozhi huozhi marked this pull request as draft January 9, 2025 17:17
@huozhi huozhi marked this pull request as ready for review January 9, 2025 19:04
@huozhi huozhi requested a review from gnoff January 9, 2025 19:06
huozhi added 2 commits January 9, 2025 20:24
add config schema

update test

use a different config

serve differently based on the config

rename
@huozhi huozhi force-pushed the huozhi/01-07-streaming_metadata_config branch from ee8180f to 048d9c9 Compare January 10, 2025 16:49
@huozhi huozhi requested a review from ztanner January 10, 2025 17:19
packages/next/src/build/index.ts Outdated Show resolved Hide resolved
packages/next/src/server/config.ts Show resolved Hide resolved
@huozhi huozhi requested a review from ztanner January 10, 2025 17:42
@huozhi huozhi merged commit d483dfa into canary Jan 10, 2025
124 of 131 checks passed
@huozhi huozhi deleted the huozhi/01-07-streaming_metadata_config branch January 10, 2025 19:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants