From dc36edbd1f3175b77113834371472e3202edd5cb Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Wed, 11 Nov 2026 03:12:12 +0000 Subject: [PATCH] Prevent repeated trace history batches at top scroll --- packages/app/src/features/runs/continuous-trace.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/app/src/features/runs/continuous-trace.tsx b/packages/app/src/features/runs/continuous-trace.tsx index 4614bba2..aca18d25 100644 --- a/packages/app/src/features/runs/continuous-trace.tsx +++ b/packages/app/src/features/runs/continuous-trace.tsx @@ -35,6 +35,7 @@ export function ContinuousTrace({ runId, revision, active, onReset, preview = fa const scrollRef = useRef(null); const followRef = useRef(true); const historyLoadingRef = useRef(false); + const historyTopArmedRef = useRef(true); const pullStartY = useRef(null); const prependAnchor = useRef<{ height: number; top: number } | null>(null); const initialAlignedRevision = useRef(null); @@ -79,7 +80,7 @@ export function ContinuousTrace({ runId, revision, active, onReset, preview = fa useEffect(() => { const changed = live.data?.reset ? live.data : pages.find(page => page.reset || page.revision !== revision); if (changed) onReset(changed.revision); }, [live.data, pages, revision, onReset]); useEffect(() => { if (live.data && !live.data.reset && live.data.revision === revision) setLiveItems(previous => [...previous, ...live.data!.items]); }, [live.data, revision]); useEffect(() => { setLiveItems([]); setExpanded(new Set()); }, [revision]); - useEffect(() => { initialAlignedRevision.current = null; followRef.current = true; }, [revision]); + useEffect(() => { initialAlignedRevision.current = null; followRef.current = true; historyTopArmedRef.current = true; }, [revision]); const updateRetainedRows = () => { const root = scrollRef.current; if (!root) return; @@ -101,7 +102,11 @@ export function ContinuousTrace({ runId, revision, active, onReset, preview = fa updateRetainedRows(); const bottom = element.scrollHeight - element.scrollTop - element.clientHeight <= 48; followRef.current = bottom; - if (element.scrollTop <= 8 && trace.hasNextPage && !trace.isFetching && !historyLoadingRef.current) void loadHistory(3); + if (element.scrollTop > 8) historyTopArmedRef.current = true; + else if (historyTopArmedRef.current && trace.hasNextPage && !trace.isFetching && !historyLoadingRef.current) { + historyTopArmedRef.current = false; + void loadHistory(3); + } }; useEffect(() => { document.addEventListener("selectionchange", updateRetainedRows);