diff --git a/src/renderer/src/components/right-sidebar/checks-panel-content.tsx b/src/renderer/src/components/right-sidebar/checks-panel-content.tsx index 24bee80a4f1..ec42d2669e8 100644 --- a/src/renderer/src/components/right-sidebar/checks-panel-content.tsx +++ b/src/renderer/src/components/right-sidebar/checks-panel-content.tsx @@ -1,6 +1,6 @@ /* eslint-disable max-lines -- Why: co-locating all checks-panel sub-components (checks list, conflict sections, threaded PR comments) keeps the shared icon/color maps in one place. */ -import React, { useCallback, useEffect, useState } from 'react' +import React, { useCallback, useEffect, useRef, useState } from 'react' import { CircleCheck, CircleX, @@ -356,23 +356,28 @@ export function ChecksList({ function CopyButton({ text }: { text: string }): React.JSX.Element { const [copied, setCopied] = useState(false) + const copiedResetTimerRef = useRef(null) - useEffect(() => { - if (!copied) { - return + const clearCopiedResetTimer = useCallback((): void => { + if (copiedResetTimerRef.current !== null) { + window.clearTimeout(copiedResetTimerRef.current) + copiedResetTimerRef.current = null } - const timeout = window.setTimeout(() => setCopied(false), 1500) - return () => window.clearTimeout(timeout) - }, [copied]) + }, []) const handleCopy = useCallback( (e: React.MouseEvent) => { e.stopPropagation() void window.api.ui.writeClipboardText(text).then(() => { + clearCopiedResetTimer() setCopied(true) + copiedResetTimerRef.current = window.setTimeout(() => { + copiedResetTimerRef.current = null + setCopied(false) + }, 1500) }) }, - [text] + [clearCopiedResetTimer, text] ) return (