Skip to content

fix: scope react-query cache invalidation per mutation - #38

Open
uditdc wants to merge 1 commit into
mainfrom
fix/12-scope-query-invalidation
Open

fix: scope react-query cache invalidation per mutation#38
uditdc wants to merge 1 commit into
mainfrom
fix/12-scope-query-invalidation

Conversation

@uditdc

@uditdc uditdc commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Closes #12

queries.ts's useGitMutation called onSettled: () => qc.invalidateQueries() unconditionally, invalidating every cache entry (log, refs, repo, status, worktrees, stashes, diffs) on every mutation — so staging a single file refetched the branch list, commit log, and stashes along with it.

Each mutation now declares a ChangeScope ('refs' | 'index' | 'worktree' | 'all') mirroring the scope its own server route already emits over SSE (bus.emit(...) in src/server/routes/*.ts), and a shared invalidateScope helper invalidates only the query groups that scope covers:

  • checkout, createBranch, createTag, fetchRemote, pushrefs (log/refs/repo)
  • stage, unstageindex (status/worktrees/diff-working)
  • commit, uncommit, pullall (both groups)
  • stashPush, stashApply, stashPopall + stashes; stashDroprefs + stashes (stashes list is only invalidated by the four stash mutations)

Acceptance criteria

  • Staging a file no longer refetches unrelated queries (e.g. branch list) — stage/unstage now only invalidate the index scope group (status, worktrees, diff/working); verified with a unit test (tests/query-invalidation.test.ts) asserting the exact key set invalidated per scope, and by reading through every mutation's mapping against its server route's bus.emit call.
  • No regression in data freshness after commit/push/checkout/etc. — each mutation's scope was derived directly from the same scope its server route already emits for the SSE-driven cross-tab refresh (src/server/routes/actions.ts, remote.ts, stash.ts), so mutation-triggered invalidation matches exactly what the server itself considers affected by that action.

pnpm typecheck, pnpm test, and pnpm build all pass.


Generated by Claude Code

Each git mutation was invalidating every cached query on settle, so
staging a file refetched the branch list, log, stashes, etc. Each
mutation now invalidates only the query groups its git command can
actually change, mirroring the scope each server route already emits
over SSE (bus.emit('refs' | 'index' | 'worktree' | 'all')).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZi4RzgNGmMDB5W4DycPhq
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.

fix: scope react-query cache invalidation per mutation

2 participants