| 1 | import { useMemo } from "react"; |
| 2 | import type { RemoteTabRefView, TabMeta } from "../lib/types"; |
| 3 | |
| 4 | /** |
| 5 | * The active remote session reference handed to the project tree. The tree |
| 6 | * keys full tree walks, ancestor expansion and its row projection on this |
| 7 | * object, so a fresh object per render re-runs all of them on every |
| 8 | * transcript delta. RemoteTabRef carries exactly hostId and workspace |
| 9 | * (desktop/remote_projects.go), so rebuilding from those primitives plus the |
| 10 | * bound session id keeps the identity stable across unrelated tab-meta |
| 11 | * refreshes too, not merely across re-renders of the same meta object. |
| 12 | */ |
| 13 | export function useActiveRemoteRef(tab: TabMeta | undefined): RemoteTabRefView | undefined { |
| 14 | const hostId = tab?.remote?.hostId; |
| 15 | const workspace = tab?.remote?.workspace; |
| 16 | const sessionId = tab?.sessionId; |
| 17 | return useMemo( |
| 18 | () => (hostId === undefined || workspace === undefined ? undefined : { hostId, workspace, sessionId }), |
| 19 | [hostId, workspace, sessionId], |
| 20 | ); |
| 21 | } |
| 22 |