Unverified Commit 5cd616fe authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Remove request from App page prerender entry point (#100331)

## Summary

Continue decoupling App Router prerendering from HTTP request objects.
Shared preparation no longer carries `req`; dynamic rendering receives
it directly. Give prerendering its own signature, removing the request
and the ignored dev context and staged fallback params arguments, and
update the Node and export callers.

## Verification

- Full bootstrap/final builds, core types, focused ESLint/Prettier, and
commit hooks passed.
- Cache Components: `fallback-shells` passed in start-turbo and
start-webpack; `instant-validation-static-shells` passed in dev-turbo.
- App directory export: `start.test.ts` and `dynamicpage.test.ts` passed
in start-turbo and start-webpack.
- Webpack `app/standalone.test.ts` passed, including Edge bundling.
- `app-static.test.ts` in both production bundlers: two POST-body
caching cases timed out; all other cases passed. A standalone Node fetch
probe, without Next.js, reproduced empty-string and
empty-URLSearchParams POST timeouts against the fixture's external data
endpoint; multipart POST succeeded.

<!-- NEXT_JS_LLM -->
parent bb129dd3
...@@ -785,13 +785,12 @@ export function createAppPageEntrypoint({ ...@@ -785,13 +785,12 @@ export function createAppPageEntrypoint({
context: AppPageRouteHandlerContext, context: AppPageRouteHandlerContext,
renderOperation: AppPageRenderOperation renderOperation: AppPageRenderOperation
) => { ) => {
const nextReq = new NodeNextRequest(req)
const nextRes = new NodeNextResponse(res) const nextRes = new NodeNextResponse(res)
const result = const result =
renderOperation === 'prerender' renderOperation === 'prerender'
? routeModule.prerender(nextReq, nextRes, context) ? routeModule.prerender(nextRes, context)
: routeModule.render(nextReq, nextRes, context) : routeModule.render(new NodeNextRequest(req), nextRes, context)
return result.finally(() => { return result.finally(() => {
if (!span) return if (!span) return
......
...@@ -96,19 +96,16 @@ export async function exportAppPage( ...@@ -96,19 +96,16 @@ export async function exportAppPage(
} }
) )
const result = await lazyPrerenderAppPage( const result = await lazyPrerenderAppPage(
nextReq,
new NodeNextResponse(res), new NodeNextResponse(res),
requestUrl, requestUrl,
pathname, pathname,
query, query,
fallbackRouteParams, fallbackRouteParams,
renderOpts, renderOpts,
undefined, // dev
sharedContext, sharedContext,
routeMatch, routeMatch,
parsedRequestHeaders, parsedRequestHeaders,
getServerActionRequestMetadata(nextReq), getServerActionRequestMetadata(nextReq)
null // stagedFallbackParams
) )
if ('error' in result) { if ('error' in result) {
......
...@@ -2537,7 +2537,6 @@ function installGlobalModuleLoadingHandlers( ...@@ -2537,7 +2537,6 @@ function installGlobalModuleLoadingHandlers(
type PreparedAppPageRender = { type PreparedAppPageRender = {
serverActionRequestMetadata: ServerActionRequestMetadata serverActionRequestMetadata: ServerActionRequestMetadata
req: BaseNextRequest
ctx: AppRenderContext ctx: AppRenderContext
metadata: AppPageRenderResultMetadata metadata: AppPageRenderResultMetadata
loaderTree: LoaderTree loaderTree: LoaderTree
...@@ -2601,7 +2600,6 @@ function initializeClientComponentLoadTracking( ...@@ -2601,7 +2600,6 @@ function initializeClientComponentLoadTracking(
} }
async function prepareAppPageRender( async function prepareAppPageRender(
req: BaseNextRequest,
res: BaseNextResponse, res: BaseNextResponse,
requestUrl: string, requestUrl: string,
url: ReturnType<typeof parseRelativeUrl>, url: ReturnType<typeof parseRelativeUrl>,
...@@ -2618,7 +2616,7 @@ async function prepareAppPageRender( ...@@ -2618,7 +2616,7 @@ async function prepareAppPageRender(
generateRequestId: GenerateRequestId, generateRequestId: GenerateRequestId,
missingPrefetchHintPolicy: MissingPrefetchHintPolicy, missingPrefetchHintPolicy: MissingPrefetchHintPolicy,
renderCapabilities: AppRenderCapabilities renderCapabilities: AppRenderCapabilities
) { ): Promise<PreparedAppPageRender> {
const isNotFoundPath = pagePath === '/404' const isNotFoundPath = pagePath === '/404'
if (isNotFoundPath) { if (isNotFoundPath) {
res.statusCode = 404 res.statusCode = 404
...@@ -2761,7 +2759,6 @@ async function prepareAppPageRender( ...@@ -2761,7 +2759,6 @@ async function prepareAppPageRender(
return { return {
serverActionRequestMetadata, serverActionRequestMetadata,
req,
ctx, ctx,
metadata, metadata,
loaderTree, loaderTree,
...@@ -2915,8 +2912,8 @@ async function prerenderAppPage({ ...@@ -2915,8 +2912,8 @@ async function prerenderAppPage({
} }
async function renderAppPage( async function renderAppPage(
req: BaseNextRequest,
{ {
req,
ctx, ctx,
metadata, metadata,
loaderTree, loaderTree,
...@@ -3229,7 +3226,6 @@ async function renderToHTMLOrFlightImpl( ...@@ -3229,7 +3226,6 @@ async function renderToHTMLOrFlightImpl(
) )
} }
const prepared = await prepareAppPageRender( const prepared = await prepareAppPageRender(
req,
res, res,
requestUrl, requestUrl,
url, url,
...@@ -3254,11 +3250,10 @@ async function renderToHTMLOrFlightImpl( ...@@ -3254,11 +3250,10 @@ async function renderToHTMLOrFlightImpl(
supportsPerSegmentPrefetching: renderOpts.cacheComponents, supportsPerSegmentPrefetching: renderOpts.cacheComponents,
} }
) )
return renderAppPage(prepared, postponedState, dev, stagedFallbackParams) return renderAppPage(req, prepared, postponedState, dev, stagedFallbackParams)
} }
async function prerenderToHTMLOrFlightImpl( async function prerenderToHTMLOrFlightImpl(
req: BaseNextRequest,
res: BaseNextResponse, res: BaseNextResponse,
requestUrl: string, requestUrl: string,
url: ReturnType<typeof parseRelativeUrl>, url: ReturnType<typeof parseRelativeUrl>,
...@@ -3281,7 +3276,6 @@ async function prerenderToHTMLOrFlightImpl( ...@@ -3281,7 +3276,6 @@ async function prerenderToHTMLOrFlightImpl(
} }
const isRoutePPREnabled = renderOpts.experimental.isRoutePPREnabled === true const isRoutePPREnabled = renderOpts.experimental.isRoutePPREnabled === true
const prepared = await prepareAppPageRender( const prepared = await prepareAppPageRender(
req,
res, res,
requestUrl, requestUrl,
url, url,
...@@ -3326,7 +3320,16 @@ export type AppPageRender = ( ...@@ -3326,7 +3320,16 @@ export type AppPageRender = (
) => Promise<RenderResult<AppPageRenderResultMetadata>> ) => Promise<RenderResult<AppPageRenderResultMetadata>>
export type AppPagePrerender = ( export type AppPagePrerender = (
...args: Parameters<AppPageRender> res: BaseNextResponse,
requestUrl: string,
pagePath: string,
query: NextParsedUrlQuery,
fallbackRouteParams: OpaqueFallbackRouteParams | null,
renderOpts: RenderOpts,
sharedContext: AppSharedContext,
routeMatch: RouteMatch,
parsedRequestHeaders: ParsedRequestHeaders,
serverActionRequestMetadata: ServerActionRequestMetadata
) => Promise<PrerenderResult> ) => Promise<PrerenderResult>
type AppPagePreparation = { type AppPagePreparation = {
...@@ -3461,14 +3464,12 @@ export const renderToHTMLOrFlight: AppPageRender = ( ...@@ -3461,14 +3464,12 @@ export const renderToHTMLOrFlight: AppPageRender = (
} }
export const prerenderToHTMLOrFlight: AppPagePrerender = ( export const prerenderToHTMLOrFlight: AppPagePrerender = (
req,
res, res,
requestUrl, requestUrl,
pagePath, pagePath,
query, query,
fallbackRouteParams, fallbackRouteParams,
renderOpts, renderOpts,
_dev,
sharedContext, sharedContext,
routeMatch, routeMatch,
parsedRequestHeaders, parsedRequestHeaders,
...@@ -3497,7 +3498,6 @@ export const prerenderToHTMLOrFlight: AppPagePrerender = ( ...@@ -3497,7 +3498,6 @@ export const prerenderToHTMLOrFlight: AppPagePrerender = (
return workAsyncStorage.run( return workAsyncStorage.run(
workStore, workStore,
prerenderToHTMLOrFlightImpl, prerenderToHTMLOrFlightImpl,
req,
res, res,
requestUrl, requestUrl,
url, url,
......
...@@ -209,24 +209,20 @@ export class AppPageRouteModule extends RouteModule< ...@@ -209,24 +209,20 @@ export class AppPageRouteModule extends RouteModule<
} }
public prerender( public prerender(
req: BaseNextRequest,
res: BaseNextResponse, res: BaseNextResponse,
context: AppPageRouteHandlerContext context: AppPageRouteHandlerContext
): Promise<PrerenderResult> { ): Promise<PrerenderResult> {
return prerenderToHTMLOrFlight( return prerenderToHTMLOrFlight(
req,
res, res,
context.requestUrl, context.requestUrl,
context.page, context.page,
context.query, context.query,
context.fallbackRouteParams, context.fallbackRouteParams,
context.renderOpts, context.renderOpts,
undefined,
context.sharedContext, context.sharedContext,
context.routeMatch, context.routeMatch,
context.parsedRequestHeaders, context.parsedRequestHeaders,
context.serverActionRequestMetadata, context.serverActionRequestMetadata
context.stagedFallbackParams
) )
} }
......
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