Skip to content

Commit 059e3da

Browse files
committed
Try to hook up generateFlight
1 parent 2fca6bc commit 059e3da

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ export async function handleAction({
379379
requestStore,
380380
serverActions,
381381
ctx,
382+
temporaryReferences,
382383
}: {
383384
req: BaseNextRequest
384385
res: BaseNextResponse
@@ -389,6 +390,7 @@ export async function handleAction({
389390
requestStore: RequestStore
390391
serverActions?: ServerActionsConfig
391392
ctx: AppRenderContext
393+
temporaryReferences: import('react-dom/server.edge').TemporaryReferencesSet
392394
}): Promise<
393395
| undefined
394396
| {
@@ -398,9 +400,6 @@ export async function handleAction({
398400
type: 'done'
399401
result: RenderResult | undefined
400402
formState?: any
401-
temporaryReferences:
402-
| import('react-dom/server.edge').TemporaryReferencesSet
403-
| undefined
404403
}
405404
> {
406405
const contentType = req.headers['content-type']
@@ -516,7 +515,6 @@ export async function handleAction({
516515
// if the page was not revalidated, we can skip the rendering the flight tree
517516
skipFlight: !staticGenerationStore.pathWasRevalidated,
518517
}),
519-
temporaryReferences: undefined,
520518
}
521519
}
522520

@@ -558,14 +556,10 @@ export async function handleAction({
558556
ctx.renderOpts.basePath,
559557
staticGenerationStore
560558
),
561-
temporaryReferences: undefined,
562559
}
563560
}
564561
}
565562

566-
let temporaryReferences:
567-
| import('react-dom/server.edge').TemporaryReferencesSet
568-
| undefined
569563
try {
570564
await actionAsyncStorage.run({ isAction: true }, async () => {
571565
if (
@@ -575,16 +569,10 @@ export async function handleAction({
575569
isWebNextRequest(req)
576570
) {
577571
// Use react-server-dom-webpack/server.edge
578-
const {
579-
createTemporaryReferenceSet,
580-
decodeReply,
581-
decodeAction,
582-
decodeFormState,
583-
} = ComponentMod
572+
const { decodeReply, decodeAction, decodeFormState } = ComponentMod
584573
if (!req.body) {
585574
throw new Error('invariant: Missing request body.')
586575
}
587-
temporaryReferences = createTemporaryReferenceSet()
588576

589577
// TODO: add body limit
590578

@@ -650,13 +638,11 @@ export async function handleAction({
650638
) {
651639
// Use react-server-dom-webpack/server.node which supports streaming
652640
const {
653-
createTemporaryReferenceSet,
654641
decodeReply,
655642
decodeReplyFromBusboy,
656643
decodeAction,
657644
decodeFormState,
658645
} = require(`./react-server.node`)
659-
temporaryReferences = createTemporaryReferenceSet()
660646

661647
const { Transform } =
662648
require('node:stream') as typeof import('node:stream')
@@ -827,7 +813,6 @@ export async function handleAction({
827813
type: 'done',
828814
result: actionResult,
829815
formState,
830-
temporaryReferences,
831816
}
832817
} catch (err) {
833818
if (isRedirectError(err)) {
@@ -854,7 +839,6 @@ export async function handleAction({
854839
ctx.renderOpts.basePath,
855840
staticGenerationStore
856841
),
857-
temporaryReferences: undefined,
858842
}
859843
}
860844

@@ -900,7 +884,6 @@ export async function handleAction({
900884
actionResult: promise,
901885
asNotFound: true,
902886
}),
903-
temporaryReferences,
904887
}
905888
}
906889
return {
@@ -935,7 +918,6 @@ export async function handleAction({
935918
skipFlight:
936919
!staticGenerationStore.pathWasRevalidated || actionWasForwarded,
937920
}),
938-
temporaryReferences,
939921
}
940922
}
941923

packages/next/src/server/app-render/app-render.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export type AppRenderContext = AppRenderBaseContext & {
150150
isNotFoundPath: boolean
151151
nonce: string | undefined
152152
res: BaseNextResponse
153+
temporaryReferences: import('react-dom/server.edge').TemporaryReferencesSet
153154
}
154155

155156
function createNotFoundLoaderTree(loaderTree: LoaderTree): LoaderTree {
@@ -367,7 +368,7 @@ async function generateFlight(
367368
{
368369
onError: ctx.flightDataRendererErrorHandler,
369370
nonce: ctx.nonce,
370-
temporaryReferences: undefined,
371+
temporaryReferences: ctx.temporaryReferences,
371372
}
372373
)
373374

@@ -863,6 +864,8 @@ async function renderToHTMLOrFlightImpl(
863864
nonce = getScriptNonceFromHeader(csp)
864865
}
865866

867+
const temporaryReferences = ComponentMod.createTemporaryReferenceSet()
868+
866869
const ctx: AppRenderContext = {
867870
...baseCtx,
868871
getDynamicParamFromSegment,
@@ -883,6 +886,7 @@ async function renderToHTMLOrFlightImpl(
883886
isNotFoundPath,
884887
nonce,
885888
res,
889+
temporaryReferences,
886890
}
887891

888892
if (isRSCRequest && !isStaticGeneration) {
@@ -922,7 +926,6 @@ async function renderToHTMLOrFlightImpl(
922926
asNotFound,
923927
tree,
924928
formState,
925-
temporaryReferences,
926929
}: RenderToStreamOptions): Promise<RenderToStreamResult> => {
927930
const tracingMetadata = getTracedMetadata(
928931
getTracer().getTracePropagationData(),
@@ -1372,6 +1375,7 @@ async function renderToHTMLOrFlightImpl(
13721375
requestStore,
13731376
serverActions,
13741377
ctx,
1378+
temporaryReferences,
13751379
})
13761380

13771381
let formState: null | any = null
@@ -1382,7 +1386,7 @@ async function renderToHTMLOrFlightImpl(
13821386
asNotFound: true,
13831387
tree: notFoundLoaderTree,
13841388
formState,
1385-
temporaryReferences: undefined,
1389+
temporaryReferences,
13861390
})
13871391

13881392
return new RenderResult(response.stream, { metadata })
@@ -1404,10 +1408,7 @@ async function renderToHTMLOrFlightImpl(
14041408
asNotFound: isNotFoundPath,
14051409
tree: loaderTree,
14061410
formState,
1407-
temporaryReferences:
1408-
actionRequestResult !== undefined
1409-
? actionRequestResult.temporaryReferences
1410-
: undefined,
1411+
temporaryReferences,
14111412
})
14121413

14131414
// If we have pending revalidates, wait until they are all resolved.

0 commit comments

Comments
 (0)