Skip to content

Commit d1bba20

Browse files
committed
use a separate request store for the restarted render
1 parent 0c73636 commit d1bba20

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,9 @@ async function renderToHTMLOrFlightImpl(
17061706
const rootParams = getRootParams(loaderTree, ctx.getDynamicParamFromSegment)
17071707
const devValidatingFallbackParams =
17081708
getRequestMeta(req, 'devValidatingFallbackParams') || null
1709-
const requestStore = createRequestStoreForRender(
1709+
1710+
const createRequestStore = createRequestStoreForRender.bind(
1711+
null,
17101712
req,
17111713
res,
17121714
url,
@@ -1719,6 +1721,7 @@ async function renderToHTMLOrFlightImpl(
17191721
renderResumeDataCache,
17201722
devValidatingFallbackParams
17211723
)
1724+
const requestStore = createRequestStore()
17221725

17231726
if (
17241727
process.env.NODE_ENV === 'development' &&
@@ -1791,7 +1794,8 @@ async function renderToHTMLOrFlightImpl(
17911794
formState,
17921795
postponedState,
17931796
metadata,
1794-
devValidatingFallbackParams
1797+
devValidatingFallbackParams,
1798+
createRequestStore
17951799
)
17961800

17971801
return new RenderResult(stream, {
@@ -1818,6 +1822,8 @@ async function renderToHTMLOrFlightImpl(
18181822
}
18191823

18201824
const stream = await renderToStreamWithTracing(
1825+
// NOTE: in Cache Components (dev), if the render is restarted, it will use a different requestStore
1826+
// than the one that we're passing in here.
18211827
requestStore,
18221828
req,
18231829
res,
@@ -1826,7 +1832,8 @@ async function renderToHTMLOrFlightImpl(
18261832
formState,
18271833
postponedState,
18281834
metadata,
1829-
devValidatingFallbackParams
1835+
devValidatingFallbackParams,
1836+
createRequestStore
18301837
)
18311838

18321839
// Invalid dynamic usages should only error the request in development.
@@ -2025,7 +2032,8 @@ async function renderToStream(
20252032
formState: any,
20262033
postponedState: PostponedState | null,
20272034
metadata: AppPageRenderResultMetadata,
2028-
devValidatingFallbackParams: OpaqueFallbackRouteParams | null
2035+
devValidatingFallbackParams: OpaqueFallbackRouteParams | null,
2036+
createRequestStore: () => RequestStore
20292037
): Promise<ReadableStream<Uint8Array>> {
20302038
const { assetPrefix, htmlRequestId, nonce, pagePath, renderOpts, requestId } =
20312039
ctx
@@ -2286,8 +2294,7 @@ async function renderToStream(
22862294

22872295
// The initial render acted as a prospective render to warm the caches.
22882296
// Now, we need to do another render.
2289-
2290-
// TODO(restart-on-cache-miss): we should use a separate request store for this instead
2297+
requestStore = createRequestStore()
22912298

22922299
// We've filled the caches, so now we can render as usual.
22932300
requestStore.prerenderResumeDataCache = null
@@ -2296,10 +2303,6 @@ async function renderToStream(
22962303
)
22972304
requestStore.cacheSignal = null
22982305

2299-
// Reset mutable fields.
2300-
requestStore.prerenderPhase = undefined
2301-
requestStore.usedDynamic = undefined
2302-
23032306
// The initial render already wrote to its debug channel. We're not using it,
23042307
// so we need to create a new one.
23052308
const finalRenderDebugChannel =

0 commit comments

Comments
 (0)