Skip to content

Phase 3: Move parsed-diff cache into React Query #355

Description

@jennings

Move the parsed-diff cache from PRReviewStore.loadedDiffs into React Query.

The problem today

useDiffLoader fetches raw diffs (via RQ), parses them, and writes the parsed form to store.loadedDiffs. Other code paths (keyboard nav, skip-block expansion) read store.getSnapshot().loadedDiffs[filename] synchronously inside effects to decide whether to re-fetch or reuse.

The change

  • Introduce useParsedDiff(filename, sha, prKey) — reads the existing immutable raw-diff query and returns the parsed form via select, or via a dedicated RQ key wrapping the parse step.
  • Synchronous "do I already have this parsed?" checks switch to queryClient.getQueryData(...).
  • Delete loadedDiffs, setLoadedDiff, setDiffLoading, loadingFiles, and the getFullDiffFromCache helper on the store.
  • useDiffLoader no longer writes to the store; it becomes a thin driver that ensures the RQ query is subscribed.

Files affected

  • src/browser/lib/queries.ts — add useParsedDiff.
  • src/browser/hooks/useDiffLoader.ts — rewrite to use RQ cache directly.
  • src/browser/contexts/pr-review/index.tsx — delete cache fields + methods.
  • src/browser/hooks/useSkipBlockExpansion.ts and useKeyboardNavigation.ts — retarget synchronous reads.

Tests

  • useParsedDiff: test with fixture raw diffs — success, error, SHA-change invalidation, cache-key stability.
  • useDiffLoader: existing fetch-trigger tests retargeted to RQ cache reads.
  • Skip-block expansion + keyboard nav: cache reads work via queryClient.getQueryData in a QueryClientProvider wrapper.
  • End-to-end style: navigating between files re-uses parsed diffs from RQ cache; no re-parse observed.

Part of #351

Depends on #352.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Default priorityimplementedVerified locally; awaiting merge to main

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions