From ba5a513f5a77478f77d2b76cf4a63d335955fd4d Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 04:05:51 -0700 Subject: [PATCH] perf: clean tab bar focus timers from root ref --- .../src/components/tab-bar/TabBar.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/tab-bar/TabBar.tsx b/src/renderer/src/components/tab-bar/TabBar.tsx index 5b8bd323aec..ff62cf518d2 100644 --- a/src/renderer/src/components/tab-bar/TabBar.tsx +++ b/src/renderer/src/components/tab-bar/TabBar.tsx @@ -315,13 +315,24 @@ function TabBarInner({ }) } } - useEffect( - () => () => { + + const clearPendingNewTabMenuFocusOnUnmountRef = useRef< + ((node: HTMLDivElement | null) => void) | null + >(null) + if (clearPendingNewTabMenuFocusOnUnmountRef.current === null) { + clearPendingNewTabMenuFocusOnUnmountRef.current = (node: HTMLDivElement | null): void => { + if (node !== null) { + return + } + // Why: the delayed focus handoff is scoped to this tab bar instance. + // A root ref cleanup cancels it at the DOM owner boundary without an + // otherwise cleanup-only React Effect. clearPendingNewTabMenuFocusAnimation() clearPendingNewTabMenuFocusRetry() - }, - [] - ) + } + } + const clearPendingNewTabMenuFocusOnUnmount = clearPendingNewTabMenuFocusOnUnmountRef.current + useEffect(() => { if (!newTabMenuOpen) { return @@ -494,6 +505,7 @@ function TabBarInner({ return (