From 7c1ffdd4cf0d86a9f73b078f1fbef3e7788321dc Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Fri, 10 Jul 2026 18:52:58 -0700 Subject: [PATCH] Refactor terminal record merge to extract snapshot-reconciliation helper Split the inline merge logic in mergeTerminalRecordsByCurrentOrder into a named mergeTerminalSnapshotWithKnownRecord function for clarity, preserving the existing behavior of keeping the last known theme when a snapshot omits it. --- mobile/src/session/mobile-terminal-records.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/mobile/src/session/mobile-terminal-records.ts b/mobile/src/session/mobile-terminal-records.ts index 3348e307898..ffe93ac29dd 100644 --- a/mobile/src/session/mobile-terminal-records.ts +++ b/mobile/src/session/mobile-terminal-records.ts @@ -116,6 +116,20 @@ function mobileSessionTabEqual( } } +// Reconcile a partial session snapshot against the last known record for the +// same terminal. The snapshot owns live fields (title, activity); the known +// theme only survives when the snapshot omits it, since lightweight snapshots +// can drop it. +function mergeTerminalSnapshotWithKnownRecord( + snapshot: TerminalRecord, + known: TerminalRecord +): TerminalRecord { + return { + ...snapshot, + terminalTheme: snapshot.terminalTheme ?? known.terminalTheme + } +} + export function mergeTerminalRecordsByCurrentOrder( terminalTabs: TerminalRecord[], currentTerminals: TerminalRecord[] @@ -128,15 +142,9 @@ export function mergeTerminalRecordsByCurrentOrder( return [ ...currentTerminals.map((terminal) => { const snapshotTerminal = terminalTabsByHandle.get(terminal.handle) - if (!snapshotTerminal) { - return terminal - } - // Why: lightweight session snapshots can omit the theme; keep the last - // known value while still accepting current title/activity fields. - return { - ...snapshotTerminal, - terminalTheme: snapshotTerminal.terminalTheme ?? terminal.terminalTheme - } + return snapshotTerminal + ? mergeTerminalSnapshotWithKnownRecord(snapshotTerminal, terminal) + : terminal }), ...terminalTabs.filter((terminal) => !currentHandles.has(terminal.handle)) ]