Skip to content

Commit 44b1e3a

Browse files
committed
inline returns into branches
1 parent 43a4869 commit 44b1e3a

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

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

+36-23
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,8 @@ export async function handleAction({
612612
'no-cache, no-store, max-age=0, must-revalidate'
613613
)
614614

615-
let boundActionArguments: unknown[] = []
616-
617615
const { actionAsyncStorage } = ComponentMod
618616

619-
let actionResult: RenderResult | undefined
620-
let formState: any | undefined
621-
let actionModId: string | undefined
622617
const actionWasForwarded = Boolean(req.headers['x-action-forwarded'])
623618

624619
if (actionId) {
@@ -646,9 +641,13 @@ export async function handleAction({
646641
}
647642

648643
try {
649-
await actionAsyncStorage.run(
644+
return await actionAsyncStorage.run(
650645
{ isAction: true },
651-
async (): Promise<void> => {
646+
async (): Promise<HandleActionResult> => {
647+
// We only use these two for fetch actions -- no-js actions handle all of this via `decodeAction`.
648+
let actionModId: string
649+
let boundActionArguments: unknown[]
650+
652651
if (
653652
// The type check here ensures that `req` is correctly typed, and the
654653
// environment variable check provides dead code elimination.
@@ -697,15 +696,20 @@ export async function handleAction({
697696
action
698697
)
699698

700-
formState = await decodeFormState(
699+
const formState = await decodeFormState(
701700
actionReturnedState,
702701
formData,
703702
serverModuleMap
704703
)
705704

706705
requestStore.phase = 'render'
706+
707707
// Skip the fetch path
708-
return
708+
return {
709+
type: 'done',
710+
result: undefined,
711+
formState,
712+
}
709713
} else {
710714
// We couldn't decode an action, so this is a non-action POST request.
711715
throw new NotAServerActionError()
@@ -862,7 +866,7 @@ export async function handleAction({
862866
action
863867
)
864868

865-
formState = await decodeFormState(
869+
const formState = await decodeFormState(
866870
actionReturnedState,
867871
formData,
868872
serverModuleMap
@@ -871,7 +875,11 @@ export async function handleAction({
871875
requestStore.phase = 'render'
872876

873877
// Skip the fetch path
874-
return
878+
return {
879+
type: 'done',
880+
result: undefined,
881+
formState,
882+
}
875883
} else {
876884
// We couldn't decode an action, so this is a non-action POST request.
877885
throw new NotAServerActionError()
@@ -953,20 +961,25 @@ export async function handleAction({
953961
requestStore,
954962
})
955963

956-
actionResult = await finalizeAndGenerateFlight(req, ctx, requestStore, {
957-
actionResult: Promise.resolve(returnVal),
958-
// if the page was not revalidated, or if the action was forwarded from another worker, we can skip the rendering the flight tree
959-
skipFlight: !workStore.pathWasRevalidated || actionWasForwarded,
960-
temporaryReferences,
961-
})
964+
const actionResult = await finalizeAndGenerateFlight(
965+
req,
966+
ctx,
967+
requestStore,
968+
{
969+
actionResult: Promise.resolve(returnVal),
970+
// if the page was not revalidated, or if the action was forwarded from another worker, we can skip the rendering the flight tree
971+
skipFlight: !workStore.pathWasRevalidated || actionWasForwarded,
972+
temporaryReferences,
973+
}
974+
)
975+
976+
return {
977+
type: 'done',
978+
result: actionResult,
979+
formState: undefined,
980+
}
962981
}
963982
)
964-
965-
return {
966-
type: 'done',
967-
result: actionResult,
968-
formState,
969-
}
970983
} catch (err) {
971984
if (err instanceof ActionNotFoundError) {
972985
console.error(err)

0 commit comments

Comments
 (0)