Restore dev-mode cache-fill timeout for 'use cache'#93055
Merged
unstubbable merged 3 commits intocanaryfrom Apr 21, 2026
Merged
Restore dev-mode cache-fill timeout for 'use cache'#93055unstubbable merged 3 commits intocanaryfrom
'use cache'#93055unstubbable merged 3 commits intocanaryfrom
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Apr 20, 2026
lubieowoce
reviewed
Apr 21, 2026
eps1lon
reviewed
Apr 21, 2026
|
|
||
| await expect(browser).toDisplayRedbox(` | ||
| { | ||
| "code": "E394", |
Member
There was a problem hiding this comment.
generic error code. can we create a specific error so that it gets a code automatically?
Contributor
Author
There was a problem hiding this comment.
I'll see whether I can make the next-error-code-swc-plugin handle this special case (error message hard-coded into the constructor of UseCacheTimeoutError) in a follow-up.
Contributor
Author
There was a problem hiding this comment.
When `'use cache'` fills during `next dev`, there was no timeout, so a stalled fill could hang the request indefinitely. This change restores a dev-mode cache-fill timeout that fires 50 seconds after the fill starts, matching the 50s timeout we already have during prerender. The timer sets `workStore.invalidDynamicUsageError` to a `UseCacheTimeoutError` and aborts the signal passed to React's `renderToReadableStream`, which errors the cache stream. From there the existing handling of `invalidDynamicUsageError` in app-render surfaces the error in the Redbox and the CLI output without any additional plumbing. Prior to PR #85747, `spawnDynamicValidationInDev` reused the prerender store and inherited the prerender cache timeout as a side effect. After that change the validation became staged-rendering based and the timeout stopped applying to dev renders. This PR closes that gap. The timeout is skipped when the render is already in the Dynamic stage, which mirrors prerender, where caches past `await connection()` aren't executed at all. The check is written as exact equality on `RenderStage.Dynamic` rather than a numeric `< Dynamic` comparison because `RenderStage.Abandoned` is numerically higher than Dynamic but semantically represents an aborted initial prospective render whose pending caches still need to be timed out while the outer flow awaits `cacheSignal.cacheReady()`. The 50s duration is shared with the prerender path via a new `USE_CACHE_FILL_TIMEOUT_MS` constant and carries a TODO to derive it from the user-configurable `staticPageGenerationTimeout`. The tests model a realistic migration hazard: a module-scoped in-flight fetch dedupe loader (the hand-rolled variant of the documented `React.cache`-based preload pattern) joined by a `'use cache'` function. That configuration deadlocks because the outer fetch is parked on the Dynamic stage in dev, or returns an intentionally hanging promise during prerender, and the cache never fills.
9f3a92b to
9f2e217
Compare
lubieowoce
approved these changes
Apr 21, 2026
Contributor
Author
|
Failures in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When
'use cache'fills duringnext dev, there was no timeout, so a stalled fill could hang the request indefinitely. This change restores a dev-mode cache-fill timeout that fires 50 seconds after the fill starts, matching the 50s timeout we already have during prerender. The timer setsworkStore.invalidDynamicUsageErrorto aUseCacheTimeoutErrorand aborts the signal passed to React'srenderToReadableStream, which errors the cache stream. From there the existing handling ofinvalidDynamicUsageErrorin app-render surfaces the error in the Redbox and the CLI output without any additional plumbing.Prior to PR #85747,
spawnDynamicValidationInDevreused the prerender store and inherited the prerender cache timeout as a side effect. After that change the validation became staged-rendering based and the timeout stopped applying to dev renders. This PR closes that gap.The timeout is skipped when the render is already in the Dynamic stage, which mirrors prerender, where caches past
await connection()aren't executed at all. The check is written as exact equality onRenderStage.Dynamicrather than a numeric< Dynamiccomparison becauseRenderStage.Abandonedis numerically higher than Dynamic but semantically represents an aborted initial prospective render whose pending caches still need to be timed out while the outer flow awaitscacheSignal.cacheReady(). The 50s duration is shared with the prerender path via a newUSE_CACHE_FILL_TIMEOUT_MSconstant and carries a TODO to derive it from the user-configurablestaticPageGenerationTimeout.The tests model a realistic migration hazard: a module-scoped in-flight fetch dedupe loader (the hand-rolled variant of the documented
React.cache-based preload pattern) joined by a'use cache'function. That configuration deadlocks because the outer fetch is parked on the Dynamic stage in dev, or returns an intentionally hanging promise during prerender, and the cache never fills.