Repository: vercel/next.js
Pull request: [cache components]: guard against setCacheStatus since its conditionally defined

<!-- 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 #

-->


Changed files:
filename: packages/next/src/server/app-render/app-render.tsx
patch: @@ -671,8 +671,8 @@ async function generateDynamicFlightRenderResultWithCachesInDev(
 
   // Before we kick off the render, we set the cache status back to it's initial state
   // in case a previous render bypassed the cache.
-  if (process.env.NODE_ENV === 'development') {
-    setCacheStatus!('ready', htmlRequestId, requestId)
+  if (process.env.NODE_ENV === 'development' && setCacheStatus) {
+    setCacheStatus('ready', htmlRequestId, requestId)
   }
 
   function onFlightDataRenderError(err: DigestedError) {
@@ -1899,9 +1899,13 @@ async function renderToHTMLOrFlightImpl(
           )
         } else {
           // Set cache status to bypass when specifically bypassing caches in dev
-          if (process.env.NODE_ENV === 'development' && bypassCachesInDev) {
+          if (
+            process.env.NODE_ENV === 'development' &&
+            bypassCachesInDev &&
+            renderOpts.setCacheStatus
+          ) {
             const { setCacheStatus } = renderOpts
-            setCacheStatus!('bypass', htmlRequestId, requestId)
+            setCacheStatus('bypass', htmlRequestId, requestId)
           }
           return generateDynamicFlightRenderResult(req, ctx, requestStore)
         }
@@ -2925,8 +2929,8 @@ async function renderWithRestartOnCacheMissInDev(
     }
   }
 
-  if (process.env.NODE_ENV === 'development') {
-    setCacheStatus!('filling', htmlRequestId, requestId)
+  if (process.env.NODE_ENV === 'development' && setCacheStatus) {
+    setCacheStatus('filling', htmlRequestId, requestId)
   }
 
   // Cache miss. We will use the initial render to fill caches, and discard its result.
@@ -2998,10 +3002,8 @@ async function renderWithRestartOnCacheMissInDev(
     )
   )
 
-  if (process.env.NODE_ENV === 'development') {
-    // TODO: Don't know if this is the right time.
-    // It's not wired up on the frontend though.
-    setCacheStatus!('filled', htmlRequestId, requestId)
+  if (process.env.NODE_ENV === 'development' && setCacheStatus) {
+    setCacheStatus('filled', htmlRequestId, requestId)
   }
 
   return {