Commit b0724308 authored by Janka Uryga's avatar Janka Uryga

use a separate request store for the restarted render

parent 270a0616
...@@ -1706,7 +1706,9 @@ async function renderToHTMLOrFlightImpl( ...@@ -1706,7 +1706,9 @@ async function renderToHTMLOrFlightImpl(
const rootParams = getRootParams(loaderTree, ctx.getDynamicParamFromSegment) const rootParams = getRootParams(loaderTree, ctx.getDynamicParamFromSegment)
const devValidatingFallbackParams = const devValidatingFallbackParams =
getRequestMeta(req, 'devValidatingFallbackParams') || null getRequestMeta(req, 'devValidatingFallbackParams') || null
const requestStore = createRequestStoreForRender(
const createRequestStore = createRequestStoreForRender.bind(
null,
req, req,
res, res,
url, url,
...@@ -1719,6 +1721,7 @@ async function renderToHTMLOrFlightImpl( ...@@ -1719,6 +1721,7 @@ async function renderToHTMLOrFlightImpl(
renderResumeDataCache, renderResumeDataCache,
devValidatingFallbackParams devValidatingFallbackParams
) )
const requestStore = createRequestStore()
if ( if (
process.env.NODE_ENV === 'development' && process.env.NODE_ENV === 'development' &&
...@@ -1791,7 +1794,8 @@ async function renderToHTMLOrFlightImpl( ...@@ -1791,7 +1794,8 @@ async function renderToHTMLOrFlightImpl(
formState, formState,
postponedState, postponedState,
metadata, metadata,
devValidatingFallbackParams devValidatingFallbackParams,
createRequestStore
) )
return new RenderResult(stream, { return new RenderResult(stream, {
...@@ -1818,6 +1822,8 @@ async function renderToHTMLOrFlightImpl( ...@@ -1818,6 +1822,8 @@ async function renderToHTMLOrFlightImpl(
} }
const stream = await renderToStreamWithTracing( const stream = await renderToStreamWithTracing(
// NOTE: in Cache Components (dev), if the render is restarted, it will use a different requestStore
// than the one that we're passing in here.
requestStore, requestStore,
req, req,
res, res,
...@@ -1826,7 +1832,8 @@ async function renderToHTMLOrFlightImpl( ...@@ -1826,7 +1832,8 @@ async function renderToHTMLOrFlightImpl(
formState, formState,
postponedState, postponedState,
metadata, metadata,
devValidatingFallbackParams devValidatingFallbackParams,
createRequestStore
) )
// Invalid dynamic usages should only error the request in development. // Invalid dynamic usages should only error the request in development.
...@@ -2025,7 +2032,8 @@ async function renderToStream( ...@@ -2025,7 +2032,8 @@ async function renderToStream(
formState: any, formState: any,
postponedState: PostponedState | null, postponedState: PostponedState | null,
metadata: AppPageRenderResultMetadata, metadata: AppPageRenderResultMetadata,
devValidatingFallbackParams: OpaqueFallbackRouteParams | null devValidatingFallbackParams: OpaqueFallbackRouteParams | null,
createRequestStore: () => RequestStore
): Promise<ReadableStream<Uint8Array>> { ): Promise<ReadableStream<Uint8Array>> {
const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } = const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } =
ctx ctx
...@@ -2286,8 +2294,7 @@ async function renderToStream( ...@@ -2286,8 +2294,7 @@ async function renderToStream(
// The initial render acted as a prospective render to warm the caches. // The initial render acted as a prospective render to warm the caches.
// Now, we need to do another render. // Now, we need to do another render.
requestStore = createRequestStore()
// TODO(restart-on-cache-miss): we should use a separate request store for this instead
// We've filled the caches, so now we can render as usual. // We've filled the caches, so now we can render as usual.
requestStore.prerenderResumeDataCache = null requestStore.prerenderResumeDataCache = null
...@@ -2296,10 +2303,6 @@ async function renderToStream( ...@@ -2296,10 +2303,6 @@ async function renderToStream(
) )
requestStore.cacheSignal = null requestStore.cacheSignal = null
// Reset mutable fields.
requestStore.prerenderPhase = undefined
requestStore.usedDynamic = undefined
// The initial render already wrote to its debug channel. We're not using it, // The initial render already wrote to its debug channel. We're not using it,
// so we need to create a new one. // so we need to create a new one.
const finalRenderDebugChannel = const finalRenderDebugChannel =
......
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