Split session screen's clearTerminalCache cleanup into a mount-only effect; included client identity in home-screen wireUp dep key via a WeakMap-derived clientKey so forceReconnect re-attaches subs. Findings addressed: - mobile/app/h/[hostId]/session/[worktreeId].tsx:436 — clearTerminalCache fires on every client identity change - mobile/app/index.tsx — useEffect deps array uses inline expression — runs every render Rebased onto current main. Co-authored-by: orca-bot <bot@stably.ai>
This commit is contained in:
co-authored by
orca-bot
parent
57d095bf6f
commit
32b88bcdc5
@@ -578,10 +578,18 @@ export default function SessionScreen() {
|
||||
// (clientRef.current.sendRequest...) keep working without churn.
|
||||
useEffect(() => {
|
||||
clientRef.current = client
|
||||
}, [client])
|
||||
|
||||
// Why: only clear terminal cache on actual unmount. Running it whenever
|
||||
// `client` changes — including the initial null → real-client transition
|
||||
// from useHostClient's async open path — would unsubscribe terminals and
|
||||
// wipe xterm state mid-subscribe on a normal session-screen mount.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
clearTerminalCache()
|
||||
}
|
||||
}, [client, clearTerminalCache])
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
// Why: deviceToken is read from host record so feature code can pass
|
||||
// `client.id` on subscribe/send for driver-state-machine identity.
|
||||
|
||||
+21
-4
@@ -88,6 +88,21 @@ function formatDuration(ms: number): string {
|
||||
return `${totalMinutes}m`
|
||||
}
|
||||
|
||||
// Why: derive a stable per-instance identity for RpcClient so the wireUp
|
||||
// effect's dep key changes when forceReconnect swaps the underlying client
|
||||
// for a host (without this, listeners stay attached to the closed client
|
||||
// and notifications/accounts subs never re-attach).
|
||||
const clientIdentities = new WeakMap<RpcClient, number>()
|
||||
let nextClientIdentity = 1
|
||||
function clientKey(client: RpcClient): number {
|
||||
let id = clientIdentities.get(client)
|
||||
if (id == null) {
|
||||
id = nextClientIdentity++
|
||||
clientIdentities.set(client, id)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
function fetchStats(
|
||||
client: RpcClient,
|
||||
setStats: (s: StatsSummary) => void,
|
||||
@@ -423,14 +438,16 @@ export default function HomeScreen() {
|
||||
return () => {
|
||||
for (const c of cleanups) c()
|
||||
}
|
||||
// Why: depend on the host-id set, not the whole allClients array, so
|
||||
// Why: depend on the host-id set AND each entry's client identity, so
|
||||
// resubscriptions don't fire on every render that produces a new
|
||||
// array reference. Client identity is stable per hostId for the
|
||||
// lifetime of the underlying transport.
|
||||
// array reference, but DO fire when forceReconnect swaps the
|
||||
// underlying client for a host (otherwise wireUp would keep firing
|
||||
// on a closed client and never re-attach to the fresh one, leaving
|
||||
// notifications/accounts subs broken until the user navigates).
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
allClients
|
||||
.map((e) => e.hostId)
|
||||
.map((e) => `${e.hostId}:${clientKey(e.client)}`)
|
||||
.sort()
|
||||
.join(',')
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user