perf: move GitHub link copy timers to handlers

Move GitHub link-copy feedback timers into handlers and fix the verified stuck-check reset case. Risk: low.
This commit is contained in:
Neil
2026-05-31 02:04:54 -07:00
committed by GitHub
parent efcfe1ca8c
commit 3aa4b36efe
2 changed files with 34 additions and 18 deletions
@@ -5312,21 +5312,24 @@ export default function GitHubItemDialog({
// Why: clipboard IPC can resolve after the dialog unmounts; skip copied-state
// feedback instead of starting its reset timer on a stale surface.
const linkCopyMountedRef = useRef(false)
const linkCopiedResetTimerRef = useRef<number | null>(null)
const clearLinkCopiedResetTimer = useCallback((): void => {
if (linkCopiedResetTimerRef.current === null) {
return
}
window.clearTimeout(linkCopiedResetTimerRef.current)
linkCopiedResetTimerRef.current = null
}, [])
const setLinkCopyButtonRef = useCallback((node: HTMLButtonElement | null) => {
linkCopyMountedRef.current = node !== null
}, [])
useEffect(() => {
clearLinkCopiedResetTimer()
setLinkCopied(false)
}, [workItemId])
}, [clearLinkCopiedResetTimer, workItemId])
useEffect(() => {
if (!linkCopied) {
return
}
const handle = window.setTimeout(() => setLinkCopied(false), 1500)
return () => window.clearTimeout(handle)
}, [linkCopied])
useEffect(() => clearLinkCopiedResetTimer, [clearLinkCopiedResetTimer])
const handleCopyWorkItemLink = useCallback(async (): Promise<void> => {
if (!workItem) {
@@ -5339,12 +5342,17 @@ export default function GitHubItemDialog({
if (!linkCopyMountedRef.current) {
return
}
clearLinkCopiedResetTimer()
setLinkCopied(true)
linkCopiedResetTimerRef.current = window.setTimeout(() => {
linkCopiedResetTimerRef.current = null
setLinkCopied(false)
}, 1500)
toast.success('GitHub link copied')
} catch {
toast.error('Failed to copy GitHub link')
}
}, [workItem])
}, [clearLinkCopiedResetTimer, workItem])
const appendOptimisticComment = useCallback(
(comment: PRComment) => {
@@ -5397,21 +5397,24 @@ export default function PullRequestPage({
// Why: clipboard IPC can resolve after the page unmounts; skip copied-state
// feedback instead of starting its reset timer on a stale surface.
const linkCopyMountedRef = useRef(false)
const linkCopiedResetTimerRef = useRef<number | null>(null)
const clearLinkCopiedResetTimer = useCallback((): void => {
if (linkCopiedResetTimerRef.current === null) {
return
}
window.clearTimeout(linkCopiedResetTimerRef.current)
linkCopiedResetTimerRef.current = null
}, [])
const setLinkCopyButtonRef = useCallback((node: HTMLButtonElement | null) => {
linkCopyMountedRef.current = node !== null
}, [])
useEffect(() => {
clearLinkCopiedResetTimer()
setLinkCopied(false)
}, [workItemId])
}, [clearLinkCopiedResetTimer, workItemId])
useEffect(() => {
if (!linkCopied) {
return
}
const handle = window.setTimeout(() => setLinkCopied(false), 1500)
return () => window.clearTimeout(handle)
}, [linkCopied])
useEffect(() => clearLinkCopiedResetTimer, [clearLinkCopiedResetTimer])
const handleCopyWorkItemLink = useCallback(async (): Promise<void> => {
if (!workItem) {
@@ -5424,12 +5427,17 @@ export default function PullRequestPage({
if (!linkCopyMountedRef.current) {
return
}
clearLinkCopiedResetTimer()
setLinkCopied(true)
linkCopiedResetTimerRef.current = window.setTimeout(() => {
linkCopiedResetTimerRef.current = null
setLinkCopied(false)
}, 1500)
toast.success('GitHub link copied')
} catch {
toast.error('Failed to copy GitHub link')
}
}, [workItem])
}, [clearLinkCopiedResetTimer, workItem])
const appendOptimisticComment = useCallback(
(comment: PRComment) => {