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