Skip to content

fix(cache): evict stale entry on SWR revalidation failure#9

Merged
pi0 merged 1 commit intomainfrom
fix/swr-issues
Mar 19, 2026
Merged

fix(cache): evict stale entry on SWR revalidation failure#9
pi0 merged 1 commit intomainfrom
fix/swr-issues

Conversation

@pi0
Copy link
Member

@pi0 pi0 commented Mar 19, 2026

Summary

  • When SWR background revalidation throws (e.g. handler returns 404), the stale cache entry is now evicted from storage
  • When SWR background revalidation returns a value that fails validation (e.g. empty/undefined), the stale cache entry is now evicted from storage
  • Previously, stale entries persisted indefinitely in both cases, causing the "stale forever" bug

Addresses upstream Nitro issues:

Changes

src/cache.ts: Added _evictFromStorage helper. Called in two places in _resolve:

  1. In the catch block — when resolver throws, evict stale entry
  2. After validate(entry) === false — when new value is invalid, evict stale entry

test/index.test.ts: Two regression tests confirming stale entries are evicted from storage after failed SWR revalidation.

Test plan

  • Regression test: SWR evicts stale entry when bg revalidation throws
  • Regression test: SWR evicts stale entry when bg revalidation result fails validation
  • All 86 tests pass

When SWR background revalidation throws or returns an invalid result
(fails `validate`), the stale cache entry is now removed from storage.
Previously, stale entries persisted indefinitely in these cases.

Fixes: nitrojs/nitro#3110, nitrojs/nitro#1992
@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Warning

Rate limit exceeded

@pi0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10d741cd-075f-4f42-b95d-517c07e9f93b

📥 Commits

Reviewing files that changed from the base of the PR and between 58616e0 and 9f75858.

📒 Files selected for processing (2)
  • src/cache.ts
  • test/index.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/swr-issues
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant