From 6b3f3ec906f91d16ece6e490970ff2423c18223c Mon Sep 17 00:00:00 2001 From: Dotta Date: Thu, 30 Apr 2026 11:35:22 -0500 Subject: [PATCH] Clear issue chat settle timers on unmount --- ui/src/components/IssueChatThread.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ui/src/components/IssueChatThread.tsx b/ui/src/components/IssueChatThread.tsx index 6a89c073ef5..1cc37011438 100644 --- a/ui/src/components/IssueChatThread.tsx +++ b/ui/src/components/IssueChatThread.tsx @@ -3101,6 +3101,7 @@ export function IssueChatThread({ const lastUserMessageIdRef = useRef(null); const spacerBaselineAnchorRef = useRef(null); const spacerInitialReserveRef = useRef(0); + const latestSettleTimeoutsRef = useRef([]); const [bottomSpacerHeight, setBottomSpacerHeight] = useState(0); const displayLiveRuns = useMemo(() => { const deduped = new Map(); @@ -3356,6 +3357,15 @@ export function IssueChatThread({ bottomAnchorRef.current?.scrollIntoView({ behavior: "smooth", block: "end" }); } + function clearLatestSettleTimeouts() { + for (const timeout of latestSettleTimeoutsRef.current) { + window.clearTimeout(timeout); + } + latestSettleTimeoutsRef.current = []; + } + + useEffect(() => clearLatestSettleTimeouts, []); + // Walks the thread by anchor and lands on the latest `comment-*` row, with // a short series of settle passes. The virtualizer estimates row sizes for // unmeasured rows, and that estimate undershoots tall markdown comments — @@ -3383,9 +3393,12 @@ export function IssueChatThread({ if (typeof window === "undefined") return; + clearLatestSettleTimeouts(); const settleDelays = [380, 760, 1140]; settleDelays.forEach((delay) => { - window.setTimeout(() => { + const timeout = window.setTimeout(() => { + latestSettleTimeoutsRef.current = latestSettleTimeoutsRef.current.filter((id) => id !== timeout); + if (typeof document === "undefined") return; const el = document.getElementById(latestCommentAnchor); if (el) { el.scrollIntoView({ behavior: "smooth", block: "end" }); @@ -3399,6 +3412,7 @@ export function IssueChatThread({ behavior: "auto", }); }, delay); + latestSettleTimeoutsRef.current.push(timeout); }); }