fix(mobile): keep chat's lease-only stream when a terminal pane unmounts

This commit is contained in:
Kelvin Amoaba
2026-11-09 07:57:02 +00:00
parent 499bf89ef8
commit ffe558f257
2 changed files with 14 additions and 14 deletions
@@ -55,6 +55,19 @@ export function useMobileSessionTerminalSubscriptionFoundation(
// react-doctor-disable-next-line react-doctor/no-ref-current-in-render
unsubscribeTerminalRef.current = unsubscribeTerminal
// An unmounted pane took its xterm with it; the next mount is a new document that needs a snapshot.
// Chat's lease-only stream never drew into the document, so it stays.
const releaseTerminalDocument = useCallback(
(handle: string) => {
if (terminalUnsubsRef.current.has(handle) && !leaseOnlyHandlesRef.current.has(handle)) {
unsubscribeTerminalRef.current(handle)
}
webReadyHandlesRef.current.delete(handle)
terminalResume.forget(handle)
},
[terminalResume]
)
const clearTerminalCache = useCallback(() => {
terminalUnsubsRef.current.forEach((unsub) => unsub())
clearNativeChatInputLease()
@@ -79,6 +92,7 @@ export function useMobileSessionTerminalSubscriptionFoundation(
getTerminalRef,
unsubscribeTerminal,
unsubscribeTerminalRef,
releaseTerminalDocument,
clearTerminalCache
}
}
@@ -42,7 +42,6 @@ export function useMobileSessionTerminalWebview(scope: MobileSessionTabSwitching
pendingSelectionRef,
activeSessionTab,
unsubscribeTerminal,
unsubscribeTerminalRef,
subscribeToTerminal,
nativeChatStream,
readMarkdownTab,
@@ -108,18 +107,6 @@ export function useMobileSessionTerminalWebview(scope: MobileSessionTabSwitching
}
}, [])
// An unmounted pane took its xterm with it; the next mount is a new document that needs a snapshot.
const releaseTerminalDocument = useCallback(
(handle: string) => {
if (terminalUnsubsRef.current.has(handle)) {
unsubscribeTerminalRef.current(handle)
}
webReadyHandlesRef.current.delete(handle)
terminalResume.forget(handle)
},
[terminalResume, terminalUnsubsRef, unsubscribeTerminalRef, webReadyHandlesRef]
)
useEffect(() => {
// Imperative handles change without layout events; inventory removal owns geometry cleanup.
const liveHandles = new Set(terminals.map((terminal) => terminal.handle))
@@ -306,7 +293,6 @@ export function useMobileSessionTerminalWebview(scope: MobileSessionTabSwitching
sendTerminalUserInput,
sendTerminalOrderedInput,
setTerminalWebViewRef,
releaseTerminalDocument,
handleTerminalWebReady,
notifyTerminalFrame,
notifyTerminalPaneFrame,