cloudflare / cloudflare/vinext
"use cache": serve stale entries while revalidating in background (Next.js #74882 / #92636)
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
## Next.js change
Next.js fixed `'use cache'` / `cacheLife` so stale (not expired) entries are returned immediately while revalidation runs in the background, instead of awaiting regeneration before responding. Previously, dynamic/server-rendered routes blocked on revalidation and only then returned the stale value (worst of both worlds). Static pages also lacked true background SWR for `'use cache'`.
**Issue:** [#74882](https://github.com/vercel/next.js/issues/74882) — `'use cache'` and `cacheLife` are not using stale data while revalidating in server-rendered (dynamic) routes
**PR:** [#92636](https://github.com/vercel/next.js/pull/92636) — `fix(use-cache): remove awaiting revalidation`
**Commit:** [`a6223ac`](https://github.com/vercel/next.js/commit/a6223ac95d5e5a2f542d9bb76bd41e7451a21c73) (merged to `canary` 2026-04-22)
**Next.js files changed:**
- `packages/next/src/server/use-cache/use-cache-wrapper.ts`
- `test/e2e/app-dir/use-cache-swr/use-cache-swr.test.ts`
- `test/e2e/app-dir/use-cache-swr/app/delayed/page.tsx`
Related Next.js follow-up (route-handler response not blocking on pending waitUntil): [#93189](https://github.com/vercel/next.js/pull/93189) / [#93146](https://github.com/vercel/next.js/issues/93146) — already tracked/closed on vinext as [#959](https://github.com/cloudflare/vinext/issues/959).
## Why this matters to vinext
vinext still has the pre-fix behavior for `"use cache"`. In `packages/vinext/src/shims/cache-runtime.ts`, a shared-cache hit is only returned when `existing.cacheState !== "stale"`. Once the entry is stale, the runtime falls through and **awaits** `runCachedFunctionWithContext(...)` — there is no path that returns the stale value and schedules a background refresh.
```ts
// packages/vinext/src/shims/cache-runtime.ts (HIT gate)
existing.cacheState !== "stale" &&
// ...
// Cache miss (or stale) — execute with context
const { result, ctx, effectiveLife } = await runCachedFunctionWithContext(...)
Contributor guide
Research direction
Start in packages/vinext/src/shims/cache-runtime.ts at the shared-cache HIT gate and the call to runCachedFunctionWithContext. Compare the intended behavior with Next.js's packages/next/src/server/use-cache/use-cache-wrapper.ts and the listed use-cache-swr end-to-end test files. Done means stale entries are returned immediately while revalidation runs in the background, including the dynamic and static cases described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100