Skip to content

Commit c6ff4d0

Browse files
authored
[cache components]: guard against setCacheStatus since its conditionally defined (#85125)
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent ce7f7a5 commit c6ff4d0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ async function generateDynamicFlightRenderResultWithCachesInDev(
671671

672672
// Before we kick off the render, we set the cache status back to it's initial state
673673
// in case a previous render bypassed the cache.
674-
if (process.env.NODE_ENV === 'development') {
675-
setCacheStatus!('ready', htmlRequestId, requestId)
674+
if (process.env.NODE_ENV === 'development' && setCacheStatus) {
675+
setCacheStatus('ready', htmlRequestId, requestId)
676676
}
677677

678678
function onFlightDataRenderError(err: DigestedError) {
@@ -1899,9 +1899,13 @@ async function renderToHTMLOrFlightImpl(
18991899
)
19001900
} else {
19011901
// Set cache status to bypass when specifically bypassing caches in dev
1902-
if (process.env.NODE_ENV === 'development' && bypassCachesInDev) {
1902+
if (
1903+
process.env.NODE_ENV === 'development' &&
1904+
bypassCachesInDev &&
1905+
renderOpts.setCacheStatus
1906+
) {
19031907
const { setCacheStatus } = renderOpts
1904-
setCacheStatus!('bypass', htmlRequestId, requestId)
1908+
setCacheStatus('bypass', htmlRequestId, requestId)
19051909
}
19061910
return generateDynamicFlightRenderResult(req, ctx, requestStore)
19071911
}
@@ -2925,8 +2929,8 @@ async function renderWithRestartOnCacheMissInDev(
29252929
}
29262930
}
29272931

2928-
if (process.env.NODE_ENV === 'development') {
2929-
setCacheStatus!('filling', htmlRequestId, requestId)
2932+
if (process.env.NODE_ENV === 'development' && setCacheStatus) {
2933+
setCacheStatus('filling', htmlRequestId, requestId)
29302934
}
29312935

29322936
// Cache miss. We will use the initial render to fill caches, and discard its result.
@@ -2998,10 +3002,8 @@ async function renderWithRestartOnCacheMissInDev(
29983002
)
29993003
)
30003004

3001-
if (process.env.NODE_ENV === 'development') {
3002-
// TODO: Don't know if this is the right time.
3003-
// It's not wired up on the frontend though.
3004-
setCacheStatus!('filled', htmlRequestId, requestId)
3005+
if (process.env.NODE_ENV === 'development' && setCacheStatus) {
3006+
setCacheStatus('filled', htmlRequestId, requestId)
30053007
}
30063008

30073009
return {

0 commit comments

Comments
 (0)