@devries-cameron20 / t3code-1 / commits / 80cf4f7945
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): the terminal button reopens the drawer after its last terminal closed (#39260)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Viktor Leukocyte committed Nov 19, 2026 at 18:50 UTC 80cf4f7945892ebb823a0a843193d9be73501973
2 files changed +53 -1
apps/web/src/terminalUiStateStore.test.ts
+19
@@ -244,6 +244,25 @@ describe("terminalUiStateStore actions", () => {
244 expect(layout().terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "new"]);
245 });
246
247 + it.each([
248 + ["unmounts right after the close", false],
249 + ["sees the closing terminal once more before it unmounts", true],
250 + ])("keeps a reopened terminal when the drawer %s", (_case, staleReconcile) => {
251 + const store = useTerminalUiStateStore.getState();
252 + store.setTerminalOpen(THREAD_REF, true);
253 + store.reconcileTerminalIds(THREAD_REF, [DEFAULT_THREAD_TERMINAL_ID], "manager-1");
254 + store.closeTerminal(THREAD_REF, DEFAULT_THREAD_TERMINAL_ID);
255 + if (staleReconcile) {
256 + store.reconcileTerminalIds(THREAD_REF, [DEFAULT_THREAD_TERMINAL_ID], "manager-1");
257 + }
258 + // The drawer is gone now, so nothing reconciles the server dropping the terminal.
259 + store.ensureTerminal(THREAD_REF, DEFAULT_THREAD_TERMINAL_ID, { open: true });
260 + store.reconcileTerminalIds(THREAD_REF, [], "manager-1");
261 +
262 + expect(layout().terminalOpen).toBe(true);
263 + expect(layout().terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]);
264 + });
265 +
266 it("keeps the surviving pane active when another client closes its split sibling", () => {
267 const store = useTerminalUiStateStore.getState();
268 store.newTerminal(THREAD_REF, "first");
apps/web/src/terminalUiStateStore.ts
+34 -1
@@ -568,6 +568,22 @@ interface TerminalServerObservation {
568 readonly snapshotId: string | symbol | undefined;
569 }
570
571 +function forgetObservedTerminalId(
572 + serverObservationsByThreadKey: Record<string, TerminalServerObservation>,
573 + threadKey: string,
574 + terminalId: string,
575 +): Record<string, TerminalServerObservation> {
576 + const observation = serverObservationsByThreadKey[threadKey];
577 + if (!observation?.ids.includes(terminalId)) {
578 + return serverObservationsByThreadKey;
579 + }
580 + const ids = observation.ids.filter((id) => id !== terminalId);
581 + if (ids.length === 0) {
582 + return removeRecordEntry(serverObservationsByThreadKey, threadKey);
583 + }
584 + return { ...serverObservationsByThreadKey, [threadKey]: { ...observation, ids } };
585 +}
586 +
587 interface TerminalUiStateStoreState {
588 serverObservationsByThreadKey: Record<string, TerminalServerObservation>;
589 terminalUiStateByThreadKey: Record<string, ThreadTerminalUiState>;
@@ -642,15 +658,32 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
658 suppression.suppressed,
659 )
660 : state.suppressedTerminalIdsByThreadKey;
661 + // A listing from before this client placed the id is about an earlier terminal, so it
662 + // must not make reconcile close the new one.
663 + const nextServerObservationsByThreadKey =
664 + suppression &&
665 + !suppression.suppressed &&
666 + !selectThreadTerminalUiState(
667 + state.terminalUiStateByThreadKey,
668 + threadRef,
669 + ).terminalIds.includes(suppression.terminalId)
670 + ? forgetObservedTerminalId(
671 + state.serverObservationsByThreadKey,
672 + terminalThreadKey(threadRef),
673 + suppression.terminalId,
674 + )
675 + : state.serverObservationsByThreadKey;
676 if (
677 nextTerminalUiStateByThreadKey === state.terminalUiStateByThreadKey &&
647 - nextSuppressedTerminalIdsByThreadKey === state.suppressedTerminalIdsByThreadKey
678 + nextSuppressedTerminalIdsByThreadKey === state.suppressedTerminalIdsByThreadKey &&
679 + nextServerObservationsByThreadKey === state.serverObservationsByThreadKey
680 ) {
681 return state;
682 }
683 return {
684 terminalUiStateByThreadKey: nextTerminalUiStateByThreadKey,
685 suppressedTerminalIdsByThreadKey: nextSuppressedTerminalIdsByThreadKey,
686 + serverObservationsByThreadKey: nextServerObservationsByThreadKey,
687 };
688 });
689 };