From ec74b842935cc02e77771e97d44f81c94c1c3eda Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 03:29:10 -0700 Subject: [PATCH] perf: move combined diff copy timer cleanup to root --- .../components/editor/CombinedDiffViewer.tsx | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/renderer/src/components/editor/CombinedDiffViewer.tsx b/src/renderer/src/components/editor/CombinedDiffViewer.tsx index 726aa493bfa..021a376ac6c 100644 --- a/src/renderer/src/components/editor/CombinedDiffViewer.tsx +++ b/src/renderer/src/components/editor/CombinedDiffViewer.tsx @@ -239,13 +239,26 @@ export default function CombinedDiffViewer({ setScrollThumb({ visible: true, top, height }) }, []) + const clearNotesCopiedResetTimer = useCallback((): void => { + if (notesCopiedResetTimerRef.current !== null) { + window.clearTimeout(notesCopiedResetTimerRef.current) + notesCopiedResetTimerRef.current = null + } + }, []) + const setScrollContainerRef = useCallback( (node: HTMLDivElement | null) => { scrollContainerRef.current = node notesCopyMountedRef.current = node !== null + if (node === null) { + // Why: copied feedback is tied to the combined-diff surface lifetime; + // the root ref unmount is the same boundary that disables stale feedback. + clearNotesCopiedResetTimer() + return + } window.requestAnimationFrame(updateCombinedDiffScrollbar) }, - [updateCombinedDiffScrollbar] + [clearNotesCopiedResetTimer, updateCombinedDiffScrollbar] ) useEffect(() => { @@ -279,14 +292,6 @@ export default function CombinedDiffViewer({ } }, [settings?.combinedDiffFileTreeVisibleByDefault]) - useEffect(() => { - return () => { - if (notesCopiedResetTimerRef.current !== null) { - window.clearTimeout(notesCopiedResetTimerRef.current) - } - } - }, []) - const setFileTreeCollapsed = useCallback((collapsed: boolean) => { combinedDiffFileTreeCollapsedPreference = collapsed setFileTreeCollapsedState(collapsed) @@ -1020,9 +1025,7 @@ export default function CombinedDiffViewer({ if (!notesCopyMountedRef.current) { return } - if (notesCopiedResetTimerRef.current !== null) { - window.clearTimeout(notesCopiedResetTimerRef.current) - } + clearNotesCopiedResetTimer() setNotesCopied(true) notesCopiedResetTimerRef.current = window.setTimeout(() => { setNotesCopied(false) @@ -1032,7 +1035,7 @@ export default function CombinedDiffViewer({ // Why: clipboard writes can fail while the app is not focused; this // mirrors the sidebar notes action and keeps the popover non-blocking. } - }, [diffCommentCount, diffCommentsPrompt]) + }, [clearNotesCopiedResetTimer, diffCommentCount, diffCommentsPrompt]) const handleConfirmClearNotes = useCallback(async (): Promise => { if (diffCommentCount === 0 || isClearingNotes) {