Replace derived-index fields on the store with hooks that memoize over React Query data + local UI state.
Fields removed from store
viewedFilenames
commentRangeLookup
commentAnchorLookup
navigableItems
Note: viewedFiles (the persisted set of user-marked-viewed filenames) stays on the store. Only the derived viewedFilenames (that resolves against current file SHAs) moves.
New hooks
useViewedFilenames() — useMemo over useFiles() result + store.viewedFiles.
useCommentRangeLookup() — useMemo over useComments() + useReviewThreads() + useFiles().
useCommentAnchorLookup() — useMemo over the same inputs.
useNavigableItems() — useMemo over useFiles() + useComments() + store.pendingComments.
Extracted pure functions
Move computeViewedFilenames, computeCommentRangeLookup, computeCommentAnchorLookup, computeNavigableItems out of the store class and into src/browser/lib/pr-review-derived.ts as pure exports. Hooks call these directly.
Consumer changes
conversations-sidebar.tsx, pr-review.tsx, useKeyboardNavigation.ts, useCommentActions.ts, useCurrentFileComments.ts — switch from usePRReviewSelector(s => s.commentRangeLookup) etc. to the new hooks.
Tests
- Port existing tests for
compute* functions directly to the new pure exports (same inputs/outputs; no wrapping).
- Test each hook wires inputs correctly under a
QueryClientProvider + PRReviewProvider.
- End-to-end style: navigating with keyboard shortcuts (which reads
navigableItems) still works.
Part of #351
Depends on #353.
Replace derived-index fields on the store with hooks that memoize over React Query data + local UI state.
Fields removed from store
viewedFilenamescommentRangeLookupcommentAnchorLookupnavigableItemsNote:
viewedFiles(the persisted set of user-marked-viewed filenames) stays on the store. Only the derivedviewedFilenames(that resolves against current file SHAs) moves.New hooks
useViewedFilenames()—useMemooveruseFiles()result +store.viewedFiles.useCommentRangeLookup()—useMemooveruseComments()+useReviewThreads()+useFiles().useCommentAnchorLookup()—useMemoover the same inputs.useNavigableItems()—useMemooveruseFiles()+useComments()+store.pendingComments.Extracted pure functions
Move
computeViewedFilenames,computeCommentRangeLookup,computeCommentAnchorLookup,computeNavigableItemsout of the store class and intosrc/browser/lib/pr-review-derived.tsas pure exports. Hooks call these directly.Consumer changes
conversations-sidebar.tsx,pr-review.tsx,useKeyboardNavigation.ts,useCommentActions.ts,useCurrentFileComments.ts— switch fromusePRReviewSelector(s => s.commentRangeLookup)etc. to the new hooks.Tests
compute*functions directly to the new pure exports (same inputs/outputs; no wrapping).QueryClientProvider+PRReviewProvider.navigableItems) still works.Part of #351
Depends on #353.