Skip to content

fix: call all revalidators per key to respect individual isPaused() states#4121

Open
dcondrey wants to merge 6 commits intovercel:mainfrom
dcondrey:dcondrey-patch-3
Open

fix: call all revalidators per key to respect individual isPaused() states#4121
dcondrey wants to merge 6 commits intovercel:mainfrom
dcondrey:dcondrey-patch-3

Conversation

@dcondrey
Copy link

@dcondrey dcondrey commented Apr 17, 2025

Summary

Fixes #2333 — when multiple components consume the same SWR key with different isPaused() configurations, only revalidators[0] was called during event revalidation. If that first revalidator belonged to a paused hook, all other (unpaused) hooks were blocked from revalidating.

  • src/index/use-swr.ts: Extract triggerRevalidators() helper that iterates all registered revalidators for error retry events instead of calling only revalidators[0]
  • src/_internal/utils/mutate.ts: Call all revalidators on MUTATE_EVENT with { dedupe: true } so every hook gets a chance to participate while avoiding redundant fetches
  • test/use-swr-revalidate.test.tsx: Add tests for multi-hook isPaused scenarios, mutate with shared keys, and error retry with multiple hooks

Test plan

  • Existing test suite passes (no regressions)
  • New test: multiple hooks sharing a key where one has isPaused: () => true — the unpaused hook still revalidates
  • New test: mutate() triggers all revalidators for a shared key with deduplication
  • New test: error retry calls all revalidators so recovery propagates to all hooks

Call all revalidators for a key to respect individual isPaused() states (vercel#2333)
@dcondrey dcondrey requested review from huozhi and shuding as code owners April 17, 2025 13:38
Use the revalidators variable
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 17, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dcondrey dcondrey changed the title Update use-swr.ts fix: call all revalidators per key to respect individual isPaused() states Mar 8, 2026
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.

Multiple consumers of the same cache key all paused if only one isPaused() evaluates to true

1 participant