fix: scope react-query cache invalidation per mutation - #38
Open
uditdc wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12
queries.ts'suseGitMutationcalledonSettled: () => 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(...)insrc/server/routes/*.ts), and a sharedinvalidateScopehelper invalidates only the query groups that scope covers:checkout,createBranch,createTag,fetchRemote,push→refs(log/refs/repo)stage,unstage→index(status/worktrees/diff-working)commit,uncommit,pull→all(both groups)stashPush,stashApply,stashPop→all+ stashes;stashDrop→refs+ stashes (stashes list is only invalidated by the four stash mutations)Acceptance criteria
stage/unstagenow only invalidate theindexscope 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'sbus.emitcall.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, andpnpm buildall pass.Generated by Claude Code