feat: replace manual optimistic mutations with TanStack DB createOptimisticAction (experimental) - #86
Open
tanvesh01 wants to merge 1 commit into
Open
feat: replace manual optimistic mutations with TanStack DB createOptimisticAction (experimental)#86tanvesh01 wants to merge 1 commit into
tanvesh01 wants to merge 1 commit into
Conversation
…misticAction Replace the three useMutation-based optimistic mutation patterns (create/reply/update review comments) with createOptimisticAction from @tanstack/db. The onMutate callback bridges to React Query's cache using refs for state stability, and the mutationFn preserves the existing Tauri invoke flow. - Delete ~60 lines of manual optimistic plumbing (cancelQueries, snapshot, restore, refetch helpers) - Replace with createOptimisticAction from @tanstack/db - Each optimistic action: synchronous onMutate (setQueryData) + async mutationFn (invoke + refetch, with manual rollback on error) - Pending state tracked via useState, tx.isPersisted.promise for awaiting completion - All 112 tests pass - Consumer interface unchanged (useReviewThreadWorkspace still works) This is Phase 1 of the TanStack DB migration — focused on the optimistic mutation layer only. The query layer (TanStack Query) remains unchanged.
|
Ready to review this PR? Stage has broken it down into 3 individual chapters for you:
Chapters generated by Stage for commit cf90651 on May 23, 2026 6:05am UTC. |
Owner
Author
🔍 Close candidate: P3 — Merge-conflict stalenessThis PR is being labeled
This PR appears to need a rebase and human review before it can proceed. It is not being closed automatically. |
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.
Summary
Phase 1 of the TanStack DB migration — replaces the manual optimistic mutation pattern in
usePullRequestReviewCommentMutationswithcreateOptimisticActionfrom@tanstack/db.What changed
useMutationinstances (create comment, reply, update comment) withcreateOptimisticActionprepareOptimisticUpdate(cancelQueries + snapshot),restoreOptimisticUpdate(rollback),refetchReviewThreads(refetch on settle)@tanstack/dband@tanstack/react-dbas dependenciessrc/lib/review-thread-optimistic.ts(pure functions, still imported)useReviewThreadWorkspacestill works unchangedArchitecture
Each
createOptimisticActionbridges to React Query's cache using refs (stable across renders) so the synchronousonMutatecallback can read the current queryKey and apply optimistic state. ThemutationFncalls the Tauri invoke as before, refetches on success, and manually restores from the snapshot on error.Test Plan
Notes
This is an experimental PR — Phase 1 of a larger TanStack DB migration. This phase targets only the mutation layer. The query layer (TanStack Query) and the broader data flow remain unchanged. Future phases would introduce TanStack DB collections for the query layer with a Tauri sync adapter.