Skip to content

fix(fetchium): refetch active queries on invalidateQueries - #17

Merged
jimmy-phantom merged 2 commits into
mainfrom
jimmy/invalidate-queries-refetch-active
May 5, 2026
Merged

jimmy-phantom merged 2 commits into
mainfrom
jimmy/invalidate-queries-refetch-active

Conversation

@jimmy-phantom

@jimmy-phantom jimmy-phantom commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • queryClient.invalidateQueries(...) previously only set updatedAt = 0 via markStale(), leaving currently-mounted consumers showing stale data until they remounted. Other reactive query libraries (React Query, SWR) refetch any query that has active observers on invalidate; this aligns with that contract.
  • markStale() now kicks a debounced refetch when the relay is currently active (tracked via a new _isActive flag set by the relay's update/deactivate hooks). Inactive relays keep their existing behavior: updatedAt = 0 plus the stale-on-activate path picks up the refetch on the next mount.
  • runDebounced() already bails when a fetch is in flight, so overlapping invalidations dedupe.
  • Patch-level changeset.

Test plan

  • new invalidate-queries.test.ts: active-query refetch, unmounted-no-refetch, params filter, dedupe
  • npm run test:unit (1133 passed)
  • npm run check-types
  • npm run lint

🤖 Generated with Claude Code

`queryClient.invalidateQueries(...)` previously only set `updatedAt = 0`
via `markStale()`, which left mounted consumers showing stale data until
they remounted — invalidation was effectively a no-op for the active
case. Other reactive query libraries (React Query, SWR) refetch active
observers on invalidate; align with that contract.

`markStale()` now kicks a debounced refetch when the relay is currently
active (tracked via a new `_isActive` flag set by the relay's
update/deactivate hooks). Inactive relays are unchanged: `updatedAt = 0`
plus the existing stale-on-activate path picks up the refetch on next
mount. `runDebounced()` already bails when a fetch is in flight, so
overlapping invalidations dedupe.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jimmy-phantom jimmy-phantom changed the title fix(fetchium): refetch active consumers on invalidateQueries fix(fetchium): refetch active queries on invalidateQueries May 5, 2026
@jimmy-phantom
jimmy-phantom merged commit 49c1207 into main May 5, 2026
1 check passed
@jimmy-phantom
jimmy-phantom deleted the jimmy/invalidate-queries-refetch-active branch May 18, 2026 15:28
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.

2 participants