AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

A Stale "Use Cache" Hit Replaces Its Own Entry In The Resume Data Cache With The Background Revalidation, So Dev Reports Uncached Data And The Runtime Prefetch Loses The Entry

When a request receives a stale cached entry from a "use cache" function, the background revalidation incorrectly replaces the saved entry in the Resume Data Cache with the pending result of the regeneration. This leads to dev-time "uncached data" errors on validation renders and in production to runtime prefetch/RSC responses missing or mixing cache versions when using cacheComponents and partialPrefetching.

highConfidence 95%Next.jsAffected V16.3.5Affected V16.3.8Affected V16.4.0Affected V16.5.0-Canary.3

Origin Analysis

The background revalidation calls saveToResumeDataCache with the pending result from the cache handler, overwriting the already-stored cloned stale entry in the request's Resume Data Cache, causing subsequent renders in the same request to await the regeneration or miss the entry.
1. Clone https://github.com/giovannetti-eric/next-use-cache-stale-dev-validation-repro and run `pnpm install`. 2. Run `pnpm repro` for dev scenarios (builtin, control, custom) to observe uncached data errors on validation renders after a stale hit. 3. Run `pnpm repro:prod` to observe missing/mixed greeting copies in RSC responses with partialPrefetching enabled. 4. The issue reproduces on Next.js 16.3.5, 16.3.8, 16.4.0, and 16.5.0-canary.3.

Fixing Code Block

Edge Case Audit

This one-line change assumes the stale entry was already cloned into the Resume Data Cache before the background revalidation starts; it is safe for the hit path. However, if a custom cache handler or a future code path skips the initial clone, the request could be left without a Resume Data Cache entry. Rollback: restore the original `saveToResumeDataCache` call. Upgrade impact: this is a hotfix not yet in an official release; test thoroughly with custom cache handlers (especially those that read Date.now() in get) and with partialPrefetching enabled, as the tiered handler's additional background get calls may still affect validation renders (workaround: set HANDLER_AGE_CHECK=false).

Ecosystem Topology