Skip to content

Commit

Permalink
Try to hook up generateFlight
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 22, 2024
1 parent 2fca6bc commit 059e3da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
24 changes: 3 additions & 21 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export async function handleAction({
requestStore,
serverActions,
ctx,
temporaryReferences,
}: {
req: BaseNextRequest
res: BaseNextResponse
Expand All @@ -389,6 +390,7 @@ export async function handleAction({
requestStore: RequestStore
serverActions?: ServerActionsConfig
ctx: AppRenderContext
temporaryReferences: import('react-dom/server.edge').TemporaryReferencesSet
}): Promise<
| undefined
| {
Expand All @@ -398,9 +400,6 @@ export async function handleAction({
type: 'done'
result: RenderResult | undefined
formState?: any
temporaryReferences:
| import('react-dom/server.edge').TemporaryReferencesSet
| undefined
}
> {
const contentType = req.headers['content-type']
Expand Down Expand Up @@ -516,7 +515,6 @@ export async function handleAction({
// if the page was not revalidated, we can skip the rendering the flight tree
skipFlight: !staticGenerationStore.pathWasRevalidated,
}),
temporaryReferences: undefined,
}
}

Expand Down Expand Up @@ -558,14 +556,10 @@ export async function handleAction({
ctx.renderOpts.basePath,
staticGenerationStore
),
temporaryReferences: undefined,
}
}
}

let temporaryReferences:
| import('react-dom/server.edge').TemporaryReferencesSet
| undefined
try {
await actionAsyncStorage.run({ isAction: true }, async () => {
if (
Expand All @@ -575,16 +569,10 @@ export async function handleAction({
isWebNextRequest(req)
) {
// Use react-server-dom-webpack/server.edge
const {
createTemporaryReferenceSet,
decodeReply,
decodeAction,
decodeFormState,
} = ComponentMod
const { decodeReply, decodeAction, decodeFormState } = ComponentMod
if (!req.body) {
throw new Error('invariant: Missing request body.')
}
temporaryReferences = createTemporaryReferenceSet()

// TODO: add body limit

Expand Down Expand Up @@ -650,13 +638,11 @@ export async function handleAction({
) {
// Use react-server-dom-webpack/server.node which supports streaming
const {
createTemporaryReferenceSet,
decodeReply,
decodeReplyFromBusboy,
decodeAction,
decodeFormState,
} = require(`./react-server.node`)
temporaryReferences = createTemporaryReferenceSet()

const { Transform } =
require('node:stream') as typeof import('node:stream')
Expand Down Expand Up @@ -827,7 +813,6 @@ export async function handleAction({
type: 'done',
result: actionResult,
formState,
temporaryReferences,
}
} catch (err) {
if (isRedirectError(err)) {
Expand All @@ -854,7 +839,6 @@ export async function handleAction({
ctx.renderOpts.basePath,
staticGenerationStore
),
temporaryReferences: undefined,
}
}

Expand Down Expand Up @@ -900,7 +884,6 @@ export async function handleAction({
actionResult: promise,
asNotFound: true,
}),
temporaryReferences,
}
}
return {
Expand Down Expand Up @@ -935,7 +918,6 @@ export async function handleAction({
skipFlight:
!staticGenerationStore.pathWasRevalidated || actionWasForwarded,
}),
temporaryReferences,
}
}

Expand Down
15 changes: 8 additions & 7 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export type AppRenderContext = AppRenderBaseContext & {
isNotFoundPath: boolean
nonce: string | undefined
res: BaseNextResponse
temporaryReferences: import('react-dom/server.edge').TemporaryReferencesSet
}

function createNotFoundLoaderTree(loaderTree: LoaderTree): LoaderTree {
Expand Down Expand Up @@ -367,7 +368,7 @@ async function generateFlight(
{
onError: ctx.flightDataRendererErrorHandler,
nonce: ctx.nonce,
temporaryReferences: undefined,
temporaryReferences: ctx.temporaryReferences,
}
)

Expand Down Expand Up @@ -863,6 +864,8 @@ async function renderToHTMLOrFlightImpl(
nonce = getScriptNonceFromHeader(csp)
}

const temporaryReferences = ComponentMod.createTemporaryReferenceSet()

const ctx: AppRenderContext = {
...baseCtx,
getDynamicParamFromSegment,
Expand All @@ -883,6 +886,7 @@ async function renderToHTMLOrFlightImpl(
isNotFoundPath,
nonce,
res,
temporaryReferences,
}

if (isRSCRequest && !isStaticGeneration) {
Expand Down Expand Up @@ -922,7 +926,6 @@ async function renderToHTMLOrFlightImpl(
asNotFound,
tree,
formState,
temporaryReferences,
}: RenderToStreamOptions): Promise<RenderToStreamResult> => {
const tracingMetadata = getTracedMetadata(
getTracer().getTracePropagationData(),
Expand Down Expand Up @@ -1372,6 +1375,7 @@ async function renderToHTMLOrFlightImpl(
requestStore,
serverActions,
ctx,
temporaryReferences,
})

let formState: null | any = null
Expand All @@ -1382,7 +1386,7 @@ async function renderToHTMLOrFlightImpl(
asNotFound: true,
tree: notFoundLoaderTree,
formState,
temporaryReferences: undefined,
temporaryReferences,
})

return new RenderResult(response.stream, { metadata })
Expand All @@ -1404,10 +1408,7 @@ async function renderToHTMLOrFlightImpl(
asNotFound: isNotFoundPath,
tree: loaderTree,
formState,
temporaryReferences:
actionRequestResult !== undefined
? actionRequestResult.temporaryReferences
: undefined,
temporaryReferences,
})

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

0 comments on commit 059e3da

Please sign in to comment.