From 71d6a30b09dad15573678cbbcfd1b2d2cfb28509 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 09:35:57 -0700 Subject: [PATCH] perf: move mobile session cache cleanup to root ref --- .../app/h/[hostId]/session/[worktreeId].tsx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/mobile/app/h/[hostId]/session/[worktreeId].tsx b/mobile/app/h/[hostId]/session/[worktreeId].tsx index fb2b78b76..f30870d9a 100644 --- a/mobile/app/h/[hostId]/session/[worktreeId].tsx +++ b/mobile/app/h/[hostId]/session/[worktreeId].tsx @@ -2146,17 +2146,6 @@ export default function SessionScreen() { } }, [client, connState]) - // 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() - } - // 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. // The shared client itself stays alive across screens; we just need @@ -2971,15 +2960,17 @@ export default function SessionScreen() { if (node !== null) { return } - // Why: route-level timers can outlive quick session changes; clear them - // from the root lifecycle without passive cleanup-only Effects. + // Why: terminal subscriptions and route-level timers must clear only on + // real route detach; client churn during mount can otherwise wipe xterm + // state mid-subscribe. toastSeqRef.current += 1 + clearTerminalCache() clearToastHideTimer() clearDelayedActionTimers() clearTerminalLiveInputFocusTimer(liveInputFocusTimerRef) stopAccessoryRepeat() }, - [clearDelayedActionTimers, clearToastHideTimer, stopAccessoryRepeat] + [clearDelayedActionTimers, clearTerminalCache, clearToastHideTimer, stopAccessoryRepeat] ) const handleSelectionMode = useCallback((handle: string, active: boolean) => {