Skip to content

feat: replace manual optimistic mutations with TanStack DB createOptimisticAction (experimental) - #86

Open
tanvesh01 wants to merge 1 commit into
mainfrom
feat/tanstack-db-optimistic-mutations
Open

feat: replace manual optimistic mutations with TanStack DB createOptimisticAction (experimental)#86
tanvesh01 wants to merge 1 commit into
mainfrom
feat/tanstack-db-optimistic-mutations

Conversation

@tanvesh01

@tanvesh01 tanvesh01 commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 1 of the TanStack DB migration — replaces the manual optimistic mutation pattern in usePullRequestReviewCommentMutations with createOptimisticAction from @tanstack/db.

What changed

  • Replaced three useMutation instances (create comment, reply, update comment) with createOptimisticAction
  • Deleted ~60 lines of manual optimistic plumbing: prepareOptimisticUpdate (cancelQueries + snapshot), restoreOptimisticUpdate (rollback), refetchReviewThreads (refetch on settle)
  • Added @tanstack/db and @tanstack/react-db as dependencies
  • Preserved the optimistic data helpers in src/lib/review-thread-optimistic.ts (pure functions, still imported)
  • Preserved the consumer interface — useReviewThreadWorkspace still works unchanged

Architecture

Before:
  onMutate: async → cancelQueries → snapshot → setQueryData
  onError:   restore snapshot
  onSettled: refetch

After:
  onMutate:  sync → snapshot → setQueryData (via createOptimisticAction)
  mutationFn: async → invoke() → refetch (success) / rollback (error)
  isPending: tracked via useState + tx.isPersisted.promise

Each createOptimisticAction bridges to React Query's cache using refs (stable across renders) so the synchronous onMutate callback can read the current queryKey and apply optimistic state. The mutationFn calls the Tauri invoke as before, refetches on success, and manually restores from the snapshot on error.

Test Plan

  • All 112 tests pass (bun test), 0 failures
  • Consumer interface unchanged
  • No regressions in review thread workspace

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.


Open in Stage

…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.
@stage-review

stage-review Bot commented May 23, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Add TanStack DB dependencies
2 Migrate review comment mutations to TanStack DB
3 Other changes
Open in Stage

Chapters generated by Stage for commit cf90651 on May 23, 2026 6:05am UTC.

@tanvesh01 tanvesh01 added the experimental Experimental feature or proof-of-concept — not ready for production label May 23, 2026
@tanvesh01

Copy link
Copy Markdown
Owner Author

This was generated by AI during repo maintenance.

🔍 Close candidate: P3 — Merge-conflict staleness

This PR is being labeled close-candidate due to stale merge conflicts:

  • Merge status: DIRTY / conflicting with current main
  • Last commit: cf90651 (feat: replace manual optimistic mutations with TanStack DB createOptimisticAction) on 2026-05-23
  • Age since last commit: more than 14 days
  • Reviews: no reviews or review requests found
  • Recent author activity: no author comments or commits after the Stage-generated chapter comment on 2026-05-23

This PR appears to need a rebase and human review before it can proceed. It is not being closed automatically.

@tanvesh01 tanvesh01 added the close-candidate PR is a candidate for closure (superseded, already applied, or stale-conflicting) label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close-candidate PR is a candidate for closure (superseded, already applied, or stale-conflicting) experimental Experimental feature or proof-of-concept — not ready for production

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant