diff --git a/apps/frontend/src/renderer/components/github-prs/hooks/useGitHubPRs.ts b/apps/frontend/src/renderer/components/github-prs/hooks/useGitHubPRs.ts index 20f3d7f2..c018d04c 100644 --- a/apps/frontend/src/renderer/components/github-prs/hooks/useGitHubPRs.ts +++ b/apps/frontend/src/renderer/components/github-prs/hooks/useGitHubPRs.ts @@ -95,16 +95,17 @@ export function useGitHubPRs( const fetchGenerationRef = useRef(0); // Get PR review state from the global store - const _prReviews = usePRReviewStore((state) => state.prReviews); + const prReviews = usePRReviewStore((state) => state.prReviews); const getPRReviewState = usePRReviewStore((state) => state.getPRReviewState); - const getActivePRReviews = usePRReviewStore((state) => state.getActivePRReviews); const setNewCommitsCheckAction = usePRReviewStore((state) => state.setNewCommitsCheck); - // Get review state for the selected PR from the store - const selectedPRReviewState = useMemo(() => { + // Get review state for the selected PR from the store - optimized with targeted selector + // Only subscribes to changes for this specific PR, not all PRs + const selectedPRReviewState = usePRReviewStore((state) => { if (!projectId || selectedPRNumber === null) return null; - return getPRReviewState(projectId, selectedPRNumber); - }, [projectId, selectedPRNumber, getPRReviewState]); + const key = `${projectId}:${selectedPRNumber}`; + return state.prReviews[key] || null; + }); // Derive values from store state - all from the same source to ensure consistency const reviewResult = selectedPRReviewState?.result ?? null; @@ -116,14 +117,19 @@ export function useGitHubPRs( // Get list of PR numbers currently being reviewed const activePRReviews = useMemo(() => { if (!projectId) return []; - return getActivePRReviews(projectId).map((review) => review.prNumber); - }, [projectId, getActivePRReviews]); + return Object.values(prReviews) + .filter((review) => review.projectId === projectId && review.isReviewing) + .map((review) => review.prNumber); + }, [projectId, prReviews]); // Helper to get review state for any PR + // Reads directly from prReviews so the callback invalidates when any review state changes, + // which is needed for usePRFiltering's memoized filteredPRs to recompute correctly const getReviewStateForPR = useCallback( (prNumber: number) => { if (!projectId) return null; - const state = getPRReviewState(projectId, prNumber); + const key = `${projectId}:${prNumber}`; + const state = prReviews[key]; if (!state) return null; return { isReviewing: state.isReviewing, @@ -135,7 +141,7 @@ export function useGitHubPRs( newCommitsCheck: state.newCommitsCheck, }; }, - [projectId, getPRReviewState] + [projectId, prReviews] ); // Use detailed PR data if available (includes files), otherwise fall back to list data