From d82f453d178a2119497e993f6a51fe1587f04f87 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 22:11:57 -0700 Subject: [PATCH] fix: cancel orchestration animation frames (#3468) --- .../OrchestrationPage.tsx | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/components/feature-wall/agents-orchestration/OrchestrationPage.tsx b/src/renderer/src/components/feature-wall/agents-orchestration/OrchestrationPage.tsx index 9ac021bb6..9f4c4fe29 100644 --- a/src/renderer/src/components/feature-wall/agents-orchestration/OrchestrationPage.tsx +++ b/src/renderer/src/components/feature-wall/agents-orchestration/OrchestrationPage.tsx @@ -96,8 +96,10 @@ export function OrchestrationPage(props: { useEffect(() => { if (active && displayedChildCount >= 2) { - requestAnimationFrame(() => drawArrow()) + const frameId = requestAnimationFrame(() => drawArrow()) + return () => cancelAnimationFrame(frameId) } + return undefined }, [active, displayedChildCount, drawArrow]) useEffect(() => { @@ -129,15 +131,25 @@ export function OrchestrationPage(props: { setRowPending({}) setCreatedChildCount(2) pendingMirror.current = {} - requestAnimationFrame(() => drawArrow()) - return + const frameId = requestAnimationFrame(() => drawArrow()) + return () => cancelAnimationFrame(frameId) } let cancelled = false const timeouts: number[] = [] + const frames = new Set() const later = (fn: () => void, ms: number): void => { timeouts.push(window.setTimeout(() => !cancelled && fn(), ms)) } + const nextFrame = (fn: () => void): void => { + const frameId = requestAnimationFrame(() => { + frames.delete(frameId) + if (!cancelled) { + fn() + } + }) + frames.add(frameId) + } const clearArrows = (): void => { const arrows = arrowsRef.current @@ -178,7 +190,7 @@ export function OrchestrationPage(props: { '' layer.appendChild(bubble) void bubble.offsetWidth - requestAnimationFrame(() => bubble.classList.add('in-flight')) + nextFrame(() => bubble.classList.add('in-flight')) later(() => { // Reveal the recipient agent on landing — that's the moment work @@ -249,6 +261,8 @@ export function OrchestrationPage(props: { return () => { cancelled = true timeouts.forEach((id) => window.clearTimeout(id)) + frames.forEach((id) => cancelAnimationFrame(id)) + frames.clear() window.removeEventListener('resize', onResize) if (cleanupLayer) { cleanupLayer.innerHTML = ''