diff --git a/mobile/app/h/[hostId]/session/[worktreeId].tsx b/mobile/app/h/[hostId]/session/[worktreeId].tsx index c7873390666..e1f09245d3d 100644 --- a/mobile/app/h/[hostId]/session/[worktreeId].tsx +++ b/mobile/app/h/[hostId]/session/[worktreeId].tsx @@ -204,6 +204,8 @@ export default function SessionScreen() { // We skip terminal.focus to avoid a race where the desktop renderer // auto-fits the pane back to desktop dimensions before the override // takes effect. + const resubscribeWithoutFocusRef = useRef<(handle: string) => void>(() => {}) + const resubscribeWithoutFocus = useCallback( (handle: string) => { unsubscribeTerminal(handle) @@ -248,7 +250,7 @@ export default function SessionScreen() { return next }) manuallyRestoredRef.current.add(handle) - resubscribeWithoutFocus(handle) + resubscribeWithoutFocusRef.current(handle) setTimeout(() => getTerminalRef(handle)?.resetZoom(), 500) } } @@ -262,9 +264,11 @@ export default function SessionScreen() { subscribingHandlesRef.current.delete(handle) })() }, - [client, getTerminalRef, unsubscribeTerminal, resubscribeWithoutFocus, updateFittedHandles] + [client, getTerminalRef, unsubscribeTerminal, updateFittedHandles] ) + resubscribeWithoutFocusRef.current = resubscribeWithoutFocus + // Why: extracted so both manual "Fit to Phone" and auto-fit-on-subscribe // can share the same measure → resize → resubscribe logic. Takes explicit // handle/rpcClient to avoid stale closure issues from subscribe callbacks.