Skip to content

Commit efd8a16

Browse files
authored
🤖 fix: prevent useReviews re-renders from cascading (#1006)
Fixes re-render issues caused by unstable callback references: - Memoize `useReviews` return object to prevent creating new object on every render - Destructure `addReview` in AIView and depend only on it (not whole `reviews` object) so `handleReviewNote` callback stays stable Without this fix, every render creates a new `reviews` object → `handleReviewNote` callback recreated → all components receiving it re-render. _Generated with mux_
1 parent 13f1e66 commit efd8a16

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

src/browser/components/AIView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,14 @@ const AIViewInner: React.FC<AIViewProps> = ({
235235
}, []);
236236

237237
// Handler for review notes from Code Review tab - adds review (starts attached)
238+
// Depend only on addReview (not whole reviews object) to keep callback stable
239+
const { addReview } = reviews;
238240
const handleReviewNote = useCallback(
239241
(data: ReviewNoteData) => {
240-
reviews.addReview(data);
242+
addReview(data);
241243
// New reviews start with status "attached" so they appear in chat input immediately
242244
},
243-
[reviews]
245+
[addReview]
244246
);
245247

246248
// Handler for manual compaction from CompactionWarning click

src/browser/hooks/useReviews.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,40 @@ export function useReviews(workspaceId: string): UseReviewsReturn {
266266
[state.reviews]
267267
);
268268

269-
return {
270-
reviews,
271-
pendingCount,
272-
attachedCount,
273-
checkedCount,
274-
attachedReviews,
275-
addReview,
276-
attachReview,
277-
detachReview,
278-
checkReview,
279-
uncheckReview,
280-
removeReview,
281-
updateReviewNote,
282-
clearChecked,
283-
clearAll,
284-
getReview,
285-
};
269+
return useMemo(
270+
() => ({
271+
reviews,
272+
pendingCount,
273+
attachedCount,
274+
checkedCount,
275+
attachedReviews,
276+
addReview,
277+
attachReview,
278+
detachReview,
279+
checkReview,
280+
uncheckReview,
281+
removeReview,
282+
updateReviewNote,
283+
clearChecked,
284+
clearAll,
285+
getReview,
286+
}),
287+
[
288+
reviews,
289+
pendingCount,
290+
attachedCount,
291+
checkedCount,
292+
attachedReviews,
293+
addReview,
294+
attachReview,
295+
detachReview,
296+
checkReview,
297+
uncheckReview,
298+
removeReview,
299+
updateReviewNote,
300+
clearChecked,
301+
clearAll,
302+
getReview,
303+
]
304+
);
286305
}

0 commit comments

Comments
 (0)