ISSUE DESCRIPTION Floating terminal auto-creates tab after user closes the last one…
- User
ISSUE DESCRIPTION
Floating terminal auto-creates tab after user closes the last one
Floating terminal auto-creates tab after user closes the last one
Symptom
When the floating terminal has a single tab open and the user clicks the X button to close it, the panel auto-creates a new terminal tab instead of closing the panel. The user has to close the panel manually via the minimize button or by closing the newly created tab again.
Steps to reproduce
- Open the floating terminal (Cmd+Alt+T on Mac / Ctrl+Alt+T on Windows/Linux)
- The panel opens with one auto-created terminal tab
- Click the X button on that tab to close it
- Expected: Panel closes cleanly
- Actual: Panel stays open with a fresh auto-created tab
Root cause
The
closeTabcallback used for the X button triggers the auto-create effect (lines 102-108 inFloatingTerminalPanel.tsx) that spawns a tab whenever the panel is open with zero tabs. The panel never closes because a replacement tab is created before the close check can run.Additionally,
closeOthersandcloseToRightcontext menu actions had stale closure bugs—they readtabs.lengthfrom the captured array inuseCallbackdependencies instead of pulling fresh state viauseAppStore.getState(), causing these callbacks to operate on outdated tab lists.Expected behavior
- Clicking X on the last terminal tab should close the floating panel (symmetric with the auto-create on open)
- The panel should remain open if a PTY exits so the user can see exit status
- Multi-tab operations (
closeOthers,closeToRight) should operate on current state, not stale captures
Why it matters
The asymmetry breaks user expectations: the panel auto-creates a tab on open (hotkey press), but closing that tab doesn't reverse the action. Users expect the X button on the last tab to dismiss the panel, not spawn an orphaned replacement.
Environment
- All platforms (macOS, Linux, Windows)
- Floating terminal feature introduced in recent releases
Evaluation contract
Bootstrap a terminal tab only when the panel transitions open. An explicit close action that removes the last tab closes the panel; a PTY exit removes its tab but must neither close the panel nor create a replacement tab. Bulk close operations must read the current store state rather than a stale render-time tab list, and
closeToRightmust follow the reconciled visible tab-bar order rather than raw backing-array order. Assistant
Now let's apply the edits. First, add the import and a ref to track prior open state.
Assistant
Now let's apply the import addition and the effect fix.
Assistant
Now let's add the
wasOpenRefand fix the bootstrap effect.Assistant
Now update the bootstrap effect to only trigger on open transition:
Assistant
No hidden characters - straightforward. Let's use
editwith line range 178:207 instead.Assistant
Now let's update the
onCloseTabcallback usage where TerminalPane closes the tab (last pane closed via Ctrl+D etc.), so it routes throughcloseFloatingTabtoo, keepingonPtyExitcallingcloseTabdirectly.Assistant
Now let's view the full diff and check for correctness/type issues.
Assistant
This looks good. Now let's check
reconcile-order.tsexport path and verify TypeScript compiles. Let's check tsconfig alias@/components.Assistant
No type errors - typecheck passed cleanly (exit code 0, no error output). Now let's run relevant existing tests.
Assistant
These don't touch FloatingTerminalPanel directly, but let's run full test suite briefly to check nothing broke, plus write a quick manual reproduction test.
Assistant
All relevant tests pass. Now let's write a quick manual reproduction test to validate the fix logic, mimicking React effect behavior, since there's no direct component test suite set up for FloatingTerminalPanel. Let's check if there's a testing-library setup used elsewhere for similar panels (e.g., TabBar.context-menu.test.ts) to model a quick script.
Assistant
This confirms the logic works as intended across all three scenarios. Let's clean up the temp file and do a final review of the diff.
Assistant
Let's also double check reconcile-order test file to confirm signature/behavior matches usage (terminalIds first positional param order).
Assistant
Signature matches usage correctly (storedOrder, terminalIds, editorIds, browserIds). Good. Let's view the final diff once more in full for a sanity check.
Assistant
This diff resolves the issue comprehensively. Let's run the full test suite once more (broader) to be safe, along with lint check on the modified file.
Assistant
These are all pre-existing native module/environment failures (better-sqlite3 bindings, node-pty, etc.) unrelated to my change. None involve
floating-terminal,tab-bar, or renderer store code I touched. Let's double confirm by checking git stash to see if these fail without my changes too.Assistant
Confirmed these failures are pre-existing environment issues unrelated to my change (native module bindings not built), present with or without my patch. My changes only touched renderer code, and the relevant renderer tests all pass.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.