Commit 9da7a501 authored by Janka Uryga's avatar Janka Uryga

avoid restartable render behavior for form actions

parent a26b3bbc
...@@ -1760,6 +1760,7 @@ async function renderToHTMLOrFlightImpl( ...@@ -1760,6 +1760,7 @@ async function renderToHTMLOrFlightImpl(
renderToStream renderToStream
) )
let didExecuteServerAction = false
let formState: null | any = null let formState: null | any = null
if (isPossibleActionRequest) { if (isPossibleActionRequest) {
// For action requests, we don't want to use the resume data cache. // For action requests, we don't want to use the resume data cache.
...@@ -1794,7 +1795,7 @@ async function renderToHTMLOrFlightImpl( ...@@ -1794,7 +1795,7 @@ async function renderToHTMLOrFlightImpl(
postponedState, postponedState,
metadata, metadata,
devValidatingFallbackParams, devValidatingFallbackParams,
createRequestStore undefined // Prevent restartable-render behavior in dev + Cache Components mode
) )
return new RenderResult(stream, { return new RenderResult(stream, {
...@@ -1811,6 +1812,7 @@ async function renderToHTMLOrFlightImpl( ...@@ -1811,6 +1812,7 @@ async function renderToHTMLOrFlightImpl(
} }
} }
didExecuteServerAction = true
// Restore the resume data cache // Restore the resume data cache
requestStore.renderResumeDataCache = renderResumeDataCache requestStore.renderResumeDataCache = renderResumeDataCache
} }
...@@ -1832,7 +1834,12 @@ async function renderToHTMLOrFlightImpl( ...@@ -1832,7 +1834,12 @@ async function renderToHTMLOrFlightImpl(
postponedState, postponedState,
metadata, metadata,
devValidatingFallbackParams, devValidatingFallbackParams,
createRequestStore // If we're rendering HTML after an action, we don't want restartable-render behavior
// because the result should be dynamic, like it is in prod.
// Also, the request store might have been mutated by the action (e.g. enabling draftMode)
// and we currently we don't copy changes over when creating a new store,
// so the restarted render wouldn't be correct.
didExecuteServerAction ? undefined : createRequestStore
) )
// Invalid dynamic usages should only error the request in development. // Invalid dynamic usages should only error the request in development.
...@@ -2032,7 +2039,7 @@ async function renderToStream( ...@@ -2032,7 +2039,7 @@ async function renderToStream(
postponedState: PostponedState | null, postponedState: PostponedState | null,
metadata: AppPageRenderResultMetadata, metadata: AppPageRenderResultMetadata,
devValidatingFallbackParams: OpaqueFallbackRouteParams | null, devValidatingFallbackParams: OpaqueFallbackRouteParams | null,
createRequestStore: () => RequestStore createRequestStore: (() => RequestStore) | undefined
): Promise<ReadableStream<Uint8Array>> { ): Promise<ReadableStream<Uint8Array>> {
const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } = const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } =
ctx ctx
...@@ -2152,7 +2159,10 @@ async function renderToStream( ...@@ -2152,7 +2159,10 @@ async function renderToStream(
// Edge routes never prerender so we don't have a Prerender environment for anything in edge runtime // Edge routes never prerender so we don't have a Prerender environment for anything in edge runtime
process.env.NEXT_RUNTIME !== 'edge' && process.env.NEXT_RUNTIME !== 'edge' &&
// We only have a Prerender environment for projects opted into cacheComponents // We only have a Prerender environment for projects opted into cacheComponents
experimental.cacheComponents experimental.cacheComponents &&
// We only do this flow if we can safely recreate the store from scratch
// (which is not the case for renders after an action)
createRequestStore
) { ) {
type RSCPayloadWithValidation = InitialRSCPayload & { type RSCPayloadWithValidation = InitialRSCPayload & {
/** Only available during cacheComponents development builds. Used for logging errors. */ /** Only available during cacheComponents development builds. Used for logging errors. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment