perf: move browser grab timer cleanup to root ref (#4158)

This commit is contained in:
Neil
2026-05-31 06:21:38 -07:00
committed by GitHub
parent 32d6424a00
commit 5efcd718b2
@@ -2516,6 +2516,18 @@ function BrowserPagePane({
}): React.JSX.Element {
const isPaintable = isActive || isAutomationVisible
const containerRef = useRef<HTMLDivElement | null>(null)
const grabToastTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined)
const annotationCopyTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined)
const setContainerRef = useCallback((node: HTMLDivElement | null): void => {
containerRef.current = node
if (node !== null) {
return
}
// Why: feedback timers are scoped to this pane owner and must not fire
// after the DOM owner is detached.
clearTimeout(grabToastTimerRef.current)
clearTimeout(annotationCopyTimerRef.current)
}, [])
const addressBarInputRef = useRef<HTMLInputElement | null>(null)
const webviewRef = useRef<Electron.WebviewTag | null>(null)
const browserTabIdRef = useRef(browserTab.id)
@@ -2653,17 +2665,6 @@ function BrowserPagePane({
below: boolean
payload: BrowserGrabPayload | null
} | null>(null)
const grabToastTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined)
const annotationCopyTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined)
// Why: clear the toast auto-dismiss timer on unmount so it cannot fire
// after the component is destroyed (prevents setState-on-unmounted warnings
// and stale rearm calls).
useEffect(() => {
return () => {
clearTimeout(grabToastTimerRef.current)
clearTimeout(annotationCopyTimerRef.current)
}
}, [])
const grabRef = useRef(grab)
grabRef.current = grab
@@ -4726,7 +4727,7 @@ function BrowserPagePane({
</div>
) : null}
<div
ref={containerRef}
ref={setContainerRef}
className="relative flex min-h-0 flex-1 overflow-hidden bg-background"
onDragOver={handleInternalFileDragOver}
onDrop={handleInternalFileDrop}