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 (