@@ -730,12 +730,13 @@ export async function handleAction({
730730 // Only warn if it's a server action, otherwise skip for other post requests
731731 warnBadServerActionRequest ( )
732732
733- const actionReturnedState =
733+ const { returnVal : actionReturnedState } =
734734 await executeActionAndPrepareForRender (
735735 action as ( ) => Promise < unknown > ,
736736 [ ] ,
737737 workStore ,
738- requestStore
738+ requestStore ,
739+ actionWasForwarded
739740 )
740741
741742 const formState = await decodeFormState (
@@ -924,12 +925,13 @@ export async function handleAction({
924925 // Only warn if it's a server action, otherwise skip for other post requests
925926 warnBadServerActionRequest ( )
926927
927- const actionReturnedState =
928+ const { returnVal : actionReturnedState } =
928929 await executeActionAndPrepareForRender (
929930 action as ( ) => Promise < unknown > ,
930931 [ ] ,
931932 workStore ,
932- requestStore
933+ requestStore ,
934+ actionWasForwarded
933935 )
934936
935937 const formState = await decodeFormState (
@@ -1023,20 +1025,16 @@ export async function handleAction({
10231025 actionId !
10241026 ]
10251027
1026- // If the page was not revalidated, or if the action was forwarded from
1027- // another worker, we can skip rendering the page.
1028- const skipPageRendering =
1029- ! workStore . pathWasRevalidated || actionWasForwarded
1030-
1031- const returnVal = await executeActionAndPrepareForRender (
1032- actionHandler ,
1033- boundActionArguments ,
1034- workStore ,
1035- requestStore ,
1036- skipPageRendering
1037- ) . finally ( ( ) => {
1038- addRevalidationHeader ( res , { workStore, requestStore } )
1039- } )
1028+ const { returnVal, skipPageRendering } =
1029+ await executeActionAndPrepareForRender (
1030+ actionHandler ,
1031+ boundActionArguments ,
1032+ workStore ,
1033+ requestStore ,
1034+ actionWasForwarded
1035+ ) . finally ( ( ) => {
1036+ addRevalidationHeader ( res , { workStore, requestStore } )
1037+ } )
10401038
10411039 // For form actions, we need to continue rendering the page.
10421040 if ( isFetchAction ) {
@@ -1170,13 +1168,24 @@ async function executeActionAndPrepareForRender<
11701168 args : Parameters < TFn > ,
11711169 workStore : WorkStore ,
11721170 requestStore : RequestStore ,
1173- skipPageRendering : boolean = false
1174- ) : Promise < Awaited < ReturnType < TFn > > > {
1171+ actionWasForwarded : boolean
1172+ ) : Promise < {
1173+ returnVal : Awaited < ReturnType < TFn > >
1174+ skipPageRendering : boolean
1175+ } > {
11751176 requestStore . phase = 'action'
1177+ let skipPageRendering = actionWasForwarded
1178+
11761179 try {
1177- return await workUnitAsyncStorage . run ( requestStore , ( ) =>
1180+ const returnVal = await workUnitAsyncStorage . run ( requestStore , ( ) =>
11781181 action . apply ( null , args )
11791182 )
1183+
1184+ // If the page was not revalidated, or if the action was forwarded from
1185+ // another worker, we can skip rendering the page.
1186+ skipPageRendering ||= ! workStore . pathWasRevalidated
1187+
1188+ return { returnVal, skipPageRendering }
11801189 } finally {
11811190 if ( ! skipPageRendering ) {
11821191 requestStore . phase = 'render'
0 commit comments