Skip to content

Phase 1: Migrate simple mirrored fetched data to React Query #353

Description

@jennings

Migrate the simple mirrored fetched data off PRReviewStore in sub-PRs by data type. Each sub-PR removes one group of fields + their setters + their load orchestration from the store, and switches consumers to the existing React Query hook in src/browser/lib/queries.ts.

Sub-PRs (one commit / one PR each)

  1. pr + files — replace usePRReviewSelector(s => s.pr) and s.files with usePullRequest / usePullRequestFiles. Delete setPr, setFiles, loading, loadingFiles.
  2. reviews + reviewThreads + comments + conversation — swap in usePullRequestReviews, useReviewThreads, usePullRequestComments, usePullRequestConversation. Delete corresponding setters and loading flags.
  3. timeline — swap in usePullRequestTimeline. Delete setTimeline, addTimelineEvent.
  4. commits + pushVersions — swap in usePullRequestCommits, usePullRequestPushVersions. Delete corresponding setters and loadVersionData, versionDataLoaded.
  5. checks + workflowRunsAwaitingApproval + branchDeleted — swap in useChecksByCommit, useWorkflowRunsByCommit, useBranchStatus. Delete setChecks, refreshChecks, getChecksStatus, checksLastUpdated, loadingChecks.
  6. currentUser — swap in useCurrentUser. Delete setCurrentUser. useCurrentUserLoader becomes redundant and is removed.

At the end, loadPRData and loadOverviewData should be empty of fetched-data population and can be deleted or reduced to no-ops.

Optimistic-update conversion

PRReviewStore currently mutates these fields locally for optimistic UX. Every call site of the following methods needs an equivalent queryClient.setQueryData(...) at the same point in the flow:

  • addPendingComment, removePendingComment, updatePendingCommentBody, updatePendingCommentWithGitHubIds (stays local — pending comments live in the store still, but any read from the RQ comments cache must merge them)
  • updateComment, deleteComment, addReply — patch pullRequestComments cache entry.
  • updateReviewThread — patch reviewThreads cache entry.
  • addConversationComment — patch pullRequestConversation cache entry.
  • addTimelineEvent — patch pullRequestTimeline cache entry.

Files affected

  • src/browser/contexts/pr-review/index.tsx — remove fields and methods.
  • All 18 consumer files (see tracking issue investigation) — switch selectors to RQ hooks.
  • src/browser/hooks/useCurrentUserLoader.ts — delete.

Tests

Per sub-PR:

  • Test each RQ hook read path in consumers (was previously covered by store fixtures; retarget the same fixtures at the hook wrapped in QueryClientProvider).
  • Test each optimistic setQueryData conversion: mid-flight cache shape + reconciled post-response shape.
  • Delete store-method tests for fields/setters that are gone in that sub-PR.
  • End-to-end style: render pr-review.tsx with mocked network for the migrated data type; confirm optimistic mutations still feel instant and reconcile correctly.

Part of #351

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Default priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions