Skip to content

Commit c58b6d9

Browse files
committed
fix(plugin-terminals): reattach to existing session on refresh instead of spawning
A reload was always starting a new shell: the sessions shared state resolves with its empty initial value and backfills the server's sessions asynchronously, so the autostart check always saw an empty list. Decide autostart from the authoritative `list` RPC and seed the initial render from it, so a refresh restores the persisted sessions (reselecting the URL-hashed one) and only spawns a shell when none exist.
1 parent 5ceb97f commit c58b6d9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

plugins/terminals/src/client/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,24 @@ export async function mountTerminals(
536536
syncSessions(full.sessions ?? [])
537537
})
538538

539-
// Each page load spawns a fresh interactive session and selects it.
540-
if (options.autostart !== false)
539+
// Reconcile from the authoritative `list` RPC. The shared state resolves
540+
// with its (empty) initial value and backfills the server's sessions
541+
// asynchronously, so reading it synchronously here can both miss existing
542+
// sessions (leaving the panel blank on refresh) and make every reload look
543+
// empty enough to spawn another shell. Seeding from `list` renders the
544+
// restored sessions immediately; syncSessions then reselects the URL-hashed
545+
// one. A new session is started only when none exist.
546+
let existing: TerminalSessionInfo[] | null = null
547+
try {
548+
existing = await rpc.call('devframes-plugin-terminals:list') as TerminalSessionInfo[]
549+
}
550+
catch {
551+
existing = null
552+
}
553+
if (existing)
554+
syncSessions(existing)
555+
const hasSessions = existing ? existing.length > 0 : views.size > 0
556+
if (options.autostart !== false && !hasSessions)
541557
void spawnAndSelect({ mode: 'interactive' })
542558

543559
const resizeObserver = typeof ResizeObserver !== 'undefined'

0 commit comments

Comments
 (0)