| 1 | import { useEffect } from "react"; |
| 2 | |
| 3 | export type ActiveTabMirror = Readonly<{ current: string | undefined }>; |
| 4 | |
| 5 | const mirror: { current: string | undefined } = { current: undefined }; |
| 6 | |
| 7 | /** |
| 8 | * Layout-committed active tab mirror. The single AppRuntime host writes it |
| 9 | * through useActiveTabMirrorCommit after each committed layout; readers are |
| 10 | * event handlers and async continuations in app-runtime owners that must |
| 11 | * never capture a stale render value. It is not a render input — presentation |
| 12 | * keeps reading the reactive activeTabId. |
| 13 | */ |
| 14 | export function activeTabMirror(): ActiveTabMirror { |
| 15 | return mirror; |
| 16 | } |
| 17 | |
| 18 | export function useActiveTabMirrorCommit(activeTabId: string | undefined): void { |
| 19 | useEffect(() => { |
| 20 | mirror.current = activeTabId; |
| 21 | }, [activeTabId]); |
| 22 | useEffect(() => () => { |
| 23 | mirror.current = undefined; |
| 24 | }, []); |
| 25 | } |
| 26 |