From 8a0fb0bae2fd7f11a1abfddc51300704dee095c5 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 00:07:34 -0700 Subject: [PATCH] fix: guard source control copy feedback (#3513) --- .../right-sidebar/SourceControl.tsx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/renderer/src/components/right-sidebar/SourceControl.tsx b/src/renderer/src/components/right-sidebar/SourceControl.tsx index dea699cd2a2..568462d305f 100644 --- a/src/renderer/src/components/right-sidebar/SourceControl.tsx +++ b/src/renderer/src/components/right-sidebar/SourceControl.tsx @@ -1030,17 +1030,30 @@ function SourceControlInner(): React.JSX.Element { const [pendingDiffCommentsClear, setPendingDiffCommentsClear] = useState(null) const [isClearingDiffComments, setIsClearingDiffComments] = useState(false) + // Why: clipboard IPC can resolve after Source Control unmounts; skip copied + // feedback instead of starting a reset timer on a stale panel. + const diffCommentsCopyMountedRef = useRef(false) useEffect(() => { return () => cancelSourceControlEditorRevealFrames(pendingCommentEditorRevealFrameIdsRef) }, []) + useEffect(() => { + diffCommentsCopyMountedRef.current = true + return () => { + diffCommentsCopyMountedRef.current = false + } + }, []) + const handleCopyDiffComments = useCallback(async (): Promise => { if (diffCommentsForActive.length === 0) { return } try { await window.api.ui.writeClipboardText(diffCommentsPrompt) + if (!diffCommentsCopyMountedRef.current) { + return + } setDiffCommentsCopied(true) } catch { // Why: swallow — clipboard write can fail when the window isn't focused. @@ -5843,6 +5856,16 @@ function DiffCommentsInlineList({ }, [comments]) const [copiedId, setCopiedId] = useState(null) + // Why: clipboard IPC can resolve after the inline notes list unmounts; skip + // copied feedback instead of starting a reset timer on a stale list. + const copiedIdMountedRef = useRef(false) + + useEffect(() => { + copiedIdMountedRef.current = true + return () => { + copiedIdMountedRef.current = false + } + }, []) // Why: auto-dismiss the per-row "copied" indicator so the button returns to // its default icon after a brief confirmation window. Matches the top-level @@ -5858,6 +5881,9 @@ function DiffCommentsInlineList({ const handleCopyOne = useCallback(async (c: DiffComment): Promise => { try { await window.api.ui.writeClipboardText(formatDiffComment(c)) + if (!copiedIdMountedRef.current) { + return + } setCopiedId(c.id) } catch { // Why: swallow — clipboard write can fail when the window isn't focused.