Skip to content

Commit fa06baa

Browse files
committed
fix no cache warnings
1 parent 57029eb commit fa06baa

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

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

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,14 @@ async function generateDynamicFlightRenderResult(
621621
const getPayload = async (
622622
// eslint-disable-next-line @typescript-eslint/no-shadow
623623
requestStore: RequestStore
624-
): Promise<RSCPayload> => {
625-
const rscPayload: RSCPayload & {
626-
/** Only available during cacheComponents development builds. Used for logging errors. */
627-
_validation?: Promise<ReactNode>
628-
_bypassCachesInDev?: React.ReactNode
629-
} = await workUnitAsyncStorage.run(
630-
requestStore,
631-
generateDynamicRSCPayload,
632-
ctx,
633-
options
634-
)
624+
) => {
625+
const rscPayload: RSCPayload & RSCPayloadDevProperties =
626+
await workUnitAsyncStorage.run(
627+
requestStore,
628+
generateDynamicRSCPayload,
629+
ctx,
630+
options
631+
)
635632
if (isBypassingCachesInDev(renderOpts, requestStore)) {
636633
rscPayload._bypassCachesInDev = createElement(
637634
WarnForBypassCachesInDev,
@@ -2279,6 +2276,12 @@ function applyMetadataFromPrerenderResult(
22792276
}
22802277
}
22812278

2279+
type RSCPayloadDevProperties = {
2280+
/** Only available during cacheComponents development builds. Used for logging errors. */
2281+
_validation?: Promise<ReactNode>
2282+
_bypassCachesInDev?: ReactNode
2283+
}
2284+
22822285
async function renderToStream(
22832286
requestStore: RequestStore,
22842287
req: BaseNextRequest,
@@ -2423,18 +2426,13 @@ async function renderToStream(
24232426
// We only have a Prerender environment for projects opted into cacheComponents
24242427
cacheComponents
24252428
) {
2426-
type RSCPayloadWithValidation = InitialRSCPayload & {
2427-
/** Only available during cacheComponents development builds. Used for logging errors. */
2428-
_validation?: Promise<ReactNode>
2429-
}
2430-
24312429
const [resolveValidation, validationOutlet] = createValidationOutlet()
24322430
let debugChannel: DebugChannelPair | undefined
24332431
const getPayload = async (
24342432
// eslint-disable-next-line @typescript-eslint/no-shadow
24352433
requestStore: RequestStore
2436-
): Promise<RSCPayloadWithValidation> => {
2437-
const payload: RSCPayloadWithValidation =
2434+
) => {
2435+
const payload: InitialRSCPayload & RSCPayloadDevProperties =
24382436
await workUnitAsyncStorage.run(
24392437
requestStore,
24402438
getRSCPayload,
@@ -2447,6 +2445,15 @@ async function renderToStream(
24472445
// because we're not going to wait for the stream to complete,
24482446
// so leaving the validation unresolved is fine.
24492447
payload._validation = validationOutlet
2448+
2449+
if (isBypassingCachesInDev(renderOpts, requestStore)) {
2450+
// Mark the RSC payload to indicate that caches were bypassed in dev.
2451+
// This lets the client know not to cache anything based on this render.
2452+
payload._bypassCachesInDev = createElement(WarnForBypassCachesInDev, {
2453+
route: workStore.route,
2454+
})
2455+
}
2456+
24502457
return payload
24512458
}
24522459

@@ -2476,7 +2483,9 @@ async function renderToStream(
24762483
} else {
24772484
// We're either bypassing caches or we can't restart the render.
24782485
// Do a dynamic render, but with (basic) environment labels.
2479-
debugChannel = createDebugChannel && createDebugChannel()
2486+
2487+
debugChannel = setReactDebugChannel && createDebugChannel()
2488+
24802489
const serverStream =
24812490
await stagedRenderToReadableStreamWithoutCachesInDev(
24822491
ctx,
@@ -2521,15 +2530,14 @@ async function renderToStream(
25212530
)
25222531
} else {
25232532
// This is a dynamic render. We don't do dynamic tracking because we're not prerendering
2524-
const RSCPayload: RSCPayload & {
2525-
_bypassCachesInDev?: React.ReactNode
2526-
} = await workUnitAsyncStorage.run(
2527-
requestStore,
2528-
getRSCPayload,
2529-
tree,
2530-
ctx,
2531-
res.statusCode === 404
2532-
)
2533+
const RSCPayload: RSCPayload & RSCPayloadDevProperties =
2534+
await workUnitAsyncStorage.run(
2535+
requestStore,
2536+
getRSCPayload,
2537+
tree,
2538+
ctx,
2539+
res.statusCode === 404
2540+
)
25332541

25342542
if (isBypassingCachesInDev(renderOpts, requestStore)) {
25352543
// Mark the RSC payload to indicate that caches were bypassed in dev.

0 commit comments

Comments
 (0)