From 40236a2363aaad7990edd7a1cdbe8670d9d52090 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 27 Jun 2026 15:27:47 -0700 Subject: [PATCH] Prevent reclaiming terminal if PTY ID does not match current pane Avoid restoring a terminal with a stale PTY ID if a different terminal has already reused the pane slot. Trigger a state override tick to make stale portals disappear instead. --- .../src/components/terminal-pane/TerminalPane.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/TerminalPane.tsx b/src/renderer/src/components/terminal-pane/TerminalPane.tsx index f6641088537..b8e8cf1ab84 100644 --- a/src/renderer/src/components/terminal-pane/TerminalPane.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalPane.tsx @@ -2267,8 +2267,13 @@ export default function TerminalPane({ async (pane: ManagedPane, ptyId: string): Promise => { // Why: local and remote runtime PTYs use different transports, but the // desktop reclaim button should have one visible recovery behavior. - // Why: the banner was rendered for this PTY; re-reading pane transport - // after a mobile disconnect race can restore a recycled pane instead. + // Why: the banner was rendered for this PTY; stale portals must disappear + // before they can reclaim a different terminal that reused this pane slot. + const currentPtyId = paneTransportsRef.current.get(pane.id)?.getPtyId() ?? null + if (currentPtyId !== ptyId) { + setOverrideTick((n) => n + 1) + return + } const restored = await restoreTerminalFitToDesktop(ptyId, settingsRef.current ?? undefined) if (restored) { scheduleRestoredTerminalRefit()