File size: 3,388 Bytes
b2cad4f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | diff --git a/packages/next/src/server/app-render/action-handler.ts b/packages/next/src/server/app-render/action-handler.ts
index 772c4c036c..1156f88da6 100644
--- a/packages/next/src/server/app-render/action-handler.ts
+++ b/packages/next/src/server/app-render/action-handler.ts
@@ -564,6 +564,20 @@ type HandleActionResult =
/** The request turned out not to be a server action. */
| null
+function getRevalidationWaitUntil(
+ workStore: WorkStore,
+ skipPageRendering: boolean
+): Promise<void> | undefined {
+ if (!skipPageRendering) {
+ // Page rendering executes pending revalidations before rendering. We only
+ // need to attach them to waitUntil when no page render will take place.
+ return undefined
+ }
+
+ const revalidatesPromise = executeRevalidates(workStore)
+ return revalidatesPromise === false ? undefined : revalidatesPromise
+}
+
export async function handleAction({
req,
res,
@@ -1241,13 +1255,6 @@ export async function handleAction({
// For form actions, we need to continue rendering the page.
if (isFetchAction) {
- // If we skip page rendering, we need to ensure pending revalidates
- // are awaited before closing the response. Otherwise, this will be
- // done after rendering the page.
- const maybeRevalidatesPromise = skipPageRendering
- ? executeRevalidates(workStore)
- : false
-
return {
type: 'done',
result: await actionAsyncStorage.exit(() =>
@@ -1255,10 +1262,10 @@ export async function handleAction({
actionResult: Promise.resolve(actionResult),
skipPageRendering,
temporaryReferences,
- waitUntil:
- maybeRevalidatesPromise === false
- ? undefined
- : maybeRevalidatesPromise,
+ waitUntil: getRevalidationWaitUntil(
+ workStore,
+ skipPageRendering
+ ),
})
),
}
@@ -1325,6 +1332,10 @@ export async function handleAction({
skipPageRendering: shouldSkipPageRendering,
actionResult: promise,
temporaryReferences,
+ waitUntil: getRevalidationWaitUntil(
+ workStore,
+ shouldSkipPageRendering
+ ),
}),
}
}
@@ -1355,17 +1366,20 @@ export async function handleAction({
// swallow error, it's gonna be handled on the client
}
+ const skipPageRendering =
+ workStore.pathWasRevalidated === undefined ||
+ workStore.pathWasRevalidated === ActionDidNotRevalidate ||
+ shouldSkipPageRendering
+
return {
type: 'done',
result: await generateFlight(req, ctx, requestStore, {
actionResult: promise,
// If the page was not revalidated, or if this is an action-only
// request, we can skip rendering the page.
- skipPageRendering:
- workStore.pathWasRevalidated === undefined ||
- workStore.pathWasRevalidated === ActionDidNotRevalidate ||
- shouldSkipPageRendering,
+ skipPageRendering,
temporaryReferences,
+ waitUntil: getRevalidationWaitUntil(workStore, skipPageRendering),
}),
}
}
|