Skip to content

Commit 8338248

Browse files
committed
avoid restartable render behavior for form actions
1 parent 9791743 commit 8338248

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/next/src/server/app-render/app-render.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ async function renderToHTMLOrFlightImpl(
17601760
renderToStream
17611761
)
17621762

1763+
let didExecuteServerAction = false
17631764
let formState: null | any = null
17641765
if (isPossibleActionRequest) {
17651766
// For action requests, we don't want to use the resume data cache.
@@ -1794,7 +1795,7 @@ async function renderToHTMLOrFlightImpl(
17941795
postponedState,
17951796
metadata,
17961797
devValidatingFallbackParams,
1797-
createRequestStore
1798+
undefined // Prevent restartable-render behavior in dev + Cache Components mode
17981799
)
17991800

18001801
return new RenderResult(stream, {
@@ -1811,6 +1812,7 @@ async function renderToHTMLOrFlightImpl(
18111812
}
18121813
}
18131814

1815+
didExecuteServerAction = true
18141816
// Restore the resume data cache
18151817
requestStore.renderResumeDataCache = renderResumeDataCache
18161818
}
@@ -1832,7 +1834,12 @@ async function renderToHTMLOrFlightImpl(
18321834
postponedState,
18331835
metadata,
18341836
devValidatingFallbackParams,
1835-
createRequestStore
1837+
// If we're rendering HTML after an action, we don't want restartable-render behavior
1838+
// because the result should be dynamic, like it is in prod.
1839+
// Also, the request store might have been mutated by the action (e.g. enabling draftMode)
1840+
// and we currently we don't copy changes over when creating a new store,
1841+
// so the restarted render wouldn't be correct.
1842+
didExecuteServerAction ? undefined : createRequestStore
18361843
)
18371844

18381845
// Invalid dynamic usages should only error the request in development.
@@ -2032,7 +2039,7 @@ async function renderToStream(
20322039
postponedState: PostponedState | null,
20332040
metadata: AppPageRenderResultMetadata,
20342041
devValidatingFallbackParams: OpaqueFallbackRouteParams | null,
2035-
createRequestStore: () => RequestStore
2042+
createRequestStore: (() => RequestStore) | undefined
20362043
): Promise<ReadableStream<Uint8Array>> {
20372044
const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } =
20382045
ctx
@@ -2152,7 +2159,10 @@ async function renderToStream(
21522159
// Edge routes never prerender so we don't have a Prerender environment for anything in edge runtime
21532160
process.env.NEXT_RUNTIME !== 'edge' &&
21542161
// We only have a Prerender environment for projects opted into cacheComponents
2155-
experimental.cacheComponents
2162+
experimental.cacheComponents &&
2163+
// We only do this flow if we can safely recreate the store from scratch
2164+
// (which is not the case for renders after an action)
2165+
createRequestStore
21562166
) {
21572167
type RSCPayloadWithValidation = InitialRSCPayload & {
21582168
/** Only available during cacheComponents development builds. Used for logging errors. */

0 commit comments

Comments
 (0)