Skip to content

Commit d4fcd03

Browse files
authored
misc: split app-render into smaller functions (#56611)
This PR splits apart the function used to render App Router pages into smaller chunks for better readability + testing. A lot of the complexity is tied by the fact that a lot of the code of the function relied on closures so I had to coalesce a lot of the captured variables used into one big context that is then passed around during render. There are a lot of things to slim down further but I don't have the energy to dig more.
1 parent 56fe014 commit d4fcd03

12 files changed

+1324
-1143
lines changed

packages/next/src/lib/metadata/metadata.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export function createMetadataComponents({
3333
pathname,
3434
searchParams,
3535
getDynamicParamFromSegment,
36-
appUsingSizeAdjust,
36+
appUsingSizeAdjustment,
3737
errorType,
3838
}: {
3939
tree: LoaderTree
4040
pathname: string
4141
searchParams: { [key: string]: any }
4242
getDynamicParamFromSegment: GetDynamicParamFromSegment
43-
appUsingSizeAdjust: boolean
43+
appUsingSizeAdjustment: boolean
4444
errorType?: 'not-found' | 'redirect'
4545
}): [React.ComponentType, React.ComponentType] {
4646
const metadataContext = {
@@ -110,7 +110,7 @@ export function createMetadataComponents({
110110
IconsMetadata({ icons: metadata.icons }),
111111
])
112112

113-
if (appUsingSizeAdjust) elements.push(<meta name="next-size-adjust" />)
113+
if (appUsingSizeAdjustment) elements.push(<meta name="next-size-adjust" />)
114114

115115
return (
116116
<>

packages/next/src/server/app-render/action-handler.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import RenderResult from '../render-result'
2222
import type { StaticGenerationStore } from '../../client/components/static-generation-async-storage.external'
2323
import { FlightRenderResult } from './flight-render-result'
24-
import type { ActionResult } from './types'
2524
import type { ActionAsyncStorage } from '../../client/components/action-async-storage.external'
2625
import {
2726
filterReqHeaders,
@@ -37,6 +36,7 @@ import {
3736
NEXT_CACHE_REVALIDATED_TAGS_HEADER,
3837
NEXT_CACHE_REVALIDATE_TAG_TOKEN_HEADER,
3938
} from '../../lib/constants'
39+
import type { AppRenderContext, GenerateFlight } from './app-render'
4040

4141
function nodeToWebReadableStream(nodeReadable: import('stream').Readable) {
4242
if (process.env.NEXT_RUNTIME !== 'edge') {
@@ -246,21 +246,18 @@ export async function handleAction({
246246
staticGenerationStore,
247247
requestStore,
248248
serverActionsBodySizeLimit,
249+
ctx,
249250
}: {
250251
req: IncomingMessage
251252
res: ServerResponse
252253
ComponentMod: any
253254
page: string
254255
serverActionsManifest: any
255-
generateFlight: (options: {
256-
actionResult: ActionResult
257-
formState?: any
258-
skipFlight: boolean
259-
asNotFound?: boolean
260-
}) => Promise<RenderResult>
256+
generateFlight: GenerateFlight
261257
staticGenerationStore: StaticGenerationStore
262258
requestStore: RequestStore
263259
serverActionsBodySizeLimit?: SizeLimit
260+
ctx: AppRenderContext
264261
}): Promise<
265262
| undefined
266263
| {
@@ -466,7 +463,7 @@ export async function handleAction({
466463
requestStore,
467464
})
468465

469-
actionResult = await generateFlight({
466+
actionResult = await generateFlight(ctx, {
470467
actionResult: Promise.resolve(returnVal),
471468
// if the page was not revalidated, we can skip the rendering the flight tree
472469
skipFlight: !staticGenerationStore.pathWasRevalidated,
@@ -533,7 +530,7 @@ export async function handleAction({
533530
} catch {}
534531
return {
535532
type: 'done',
536-
result: await generateFlight({
533+
result: await generateFlight(ctx, {
537534
skipFlight: false,
538535
actionResult: promise,
539536
asNotFound: true,
@@ -555,7 +552,7 @@ export async function handleAction({
555552

556553
return {
557554
type: 'done',
558-
result: await generateFlight({
555+
result: await generateFlight(ctx, {
559556
actionResult: promise,
560557
// if the page was not revalidated, we can skip the rendering the flight tree
561558
skipFlight: !staticGenerationStore.pathWasRevalidated,

0 commit comments

Comments
 (0)