@@ -612,13 +612,8 @@ export async function handleAction({
612
612
'no-cache, no-store, max-age=0, must-revalidate'
613
613
)
614
614
615
- let boundActionArguments : unknown [ ] = [ ]
616
-
617
615
const { actionAsyncStorage } = ComponentMod
618
616
619
- let actionResult : RenderResult | undefined
620
- let formState : any | undefined
621
- let actionModId : string | undefined
622
617
const actionWasForwarded = Boolean ( req . headers [ 'x-action-forwarded' ] )
623
618
624
619
if ( actionId ) {
@@ -646,9 +641,13 @@ export async function handleAction({
646
641
}
647
642
648
643
try {
649
- await actionAsyncStorage . run (
644
+ return await actionAsyncStorage . run (
650
645
{ 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
+
652
651
if (
653
652
// The type check here ensures that `req` is correctly typed, and the
654
653
// environment variable check provides dead code elimination.
@@ -697,15 +696,20 @@ export async function handleAction({
697
696
action
698
697
)
699
698
700
- formState = await decodeFormState (
699
+ const formState = await decodeFormState (
701
700
actionReturnedState ,
702
701
formData ,
703
702
serverModuleMap
704
703
)
705
704
706
705
requestStore . phase = 'render'
706
+
707
707
// Skip the fetch path
708
- return
708
+ return {
709
+ type : 'done' ,
710
+ result : undefined ,
711
+ formState,
712
+ }
709
713
} else {
710
714
// We couldn't decode an action, so this is a non-action POST request.
711
715
throw new NotAServerActionError ( )
@@ -862,7 +866,7 @@ export async function handleAction({
862
866
action
863
867
)
864
868
865
- formState = await decodeFormState (
869
+ const formState = await decodeFormState (
866
870
actionReturnedState ,
867
871
formData ,
868
872
serverModuleMap
@@ -871,7 +875,11 @@ export async function handleAction({
871
875
requestStore . phase = 'render'
872
876
873
877
// Skip the fetch path
874
- return
878
+ return {
879
+ type : 'done' ,
880
+ result : undefined ,
881
+ formState,
882
+ }
875
883
} else {
876
884
// We couldn't decode an action, so this is a non-action POST request.
877
885
throw new NotAServerActionError ( )
@@ -953,20 +961,25 @@ export async function handleAction({
953
961
requestStore,
954
962
} )
955
963
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
+ }
962
981
}
963
982
)
964
-
965
- return {
966
- type : 'done' ,
967
- result : actionResult ,
968
- formState,
969
- }
970
983
} catch ( err ) {
971
984
if ( err instanceof ActionNotFoundError ) {
972
985
console . error ( err )
0 commit comments