cloudflare / cloudflare/vinext

[nextjs-tracker] Cache Components: deduplicate background revalidation for stale entries

Open
#3,228 0 comments 0 reactions 0 assignees View on GitHub
nextjs-tracking
Dominant language
TypeScript
Stars
8.8k
Forks
406
Avg merge
2d 6h
Merged PRs (30d)
120

Description

## Next.js Change

**Commit:** [`ac55fd9`](https://github.com/vercel/next.js/commit/ac55fd99655e29abdabfeec93dec69f7cf8c7aab)
**PR:** [#98446](https://github.com/vercel/next.js/pull/98446)

## What changed

Next.js now tracks background revalidation work independently for each `'use cache'` lookup key. Requests that observe a stale entry return that stale value while an existing regeneration and its cache writes complete; they neither wait for that work nor start a duplicate regeneration. The task is registered before generation begins and remains registered through cache persistence, including slow handler reads and writes.

## Impact on vinext

Vinext implements `'use cache'` and stale-while-revalidate caching. Its revalidation deduplication must cover background work through persistence, not only generation, or concurrent stale reads can invoke cache functions multiple times and cause duplicate side effects.

## Acceptance criteria

- [ ] Track in-flight background revalidations by the resolved cache lookup key.
- [ ] Register the task before it can begin generation and remove it only after generation, stream cleanup, and cache writes settle.
- [ ] Serve the existing stale entry immediately while matching background work is in flight.
- [ ] Avoid a second regeneration when a slow cache read returns an entry that was stale at lookup start.
- [ ] Preserve independent revalidation for distinct root-parameter-specific keys.
- [ ] Add focused regression coverage for concurrent stale reads, tag revalidation, slow reads, and slow cache writes.

Contributor guide

Open the contributing guide

Research direction

Start by tracing vinext's 'use cache' and stale-while-revalidate implementation, especially how it resolves lookup keys and persists regenerated entries. Add focused regression coverage for concurrent stale reads, tag revalidation, slow reads, and slow cache writes. Done means stale values return immediately, matching background work is deduplicated through stream cleanup and cache writes, and distinct root-parameter-specific keys revalidate independently.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript
Domain
backend, performance, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.