diff --git a/mobile/src/terminal/session/use-mobile-session-terminal-subscription-foundation.ts b/mobile/src/terminal/session/use-mobile-session-terminal-subscription-foundation.ts index 4fc6877d186..4ba5cd3f9e0 100644 --- a/mobile/src/terminal/session/use-mobile-session-terminal-subscription-foundation.ts +++ b/mobile/src/terminal/session/use-mobile-session-terminal-subscription-foundation.ts @@ -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 } } diff --git a/mobile/src/terminal/session/use-mobile-session-terminal-webview.ts b/mobile/src/terminal/session/use-mobile-session-terminal-webview.ts index 1fe429089ba..6e708c90789 100644 --- a/mobile/src/terminal/session/use-mobile-session-terminal-webview.ts +++ b/mobile/src/terminal/session/use-mobile-session-terminal-webview.ts @@ -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,