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.
This commit is contained in:
Jinjing
2026-06-27 15:27:47 -07:00
parent 58d9ba7da3
commit 40236a2363
@@ -2267,8 +2267,13 @@ export default function TerminalPane({
async (pane: ManagedPane, ptyId: string): Promise<void> => {
// 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()