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
Let me start by understanding the repository structure and finding the relevant file mentioned in the issue:
FloatingTerminalPanel.tsx.Assistant
Found it. Let me open it and examine the contents.
Assistant
Let me scroll down to see the auto-create effect and the close handlers
Assistant
Now I can see the issues:
-
Auto-create effect (lines 97-103): The effect triggers whenever
open && tabs.length === 0. When the user closes the last tab via X button,closeTabreducestabs.lengthto 0, which then triggers this effect to create a new tab. So the panel never closes. -
closeOthers(lines 176-185): Usestabsfrom the closure, which can be stale. -
closeToRight(lines 187-198): Usestabsfrom the closure, which can be stale. Also uses raw backing-array order instead of tab-bar order. -
closeFloatingTab(lines 169-174): Just callscloseTab. May need to handle the case where the last tab is closed — it should close the panel.
Let me see more of the file to understand the full picture.
-
Assistant
Let me scroll further to see TabBar usage and the rest of the component.
Assistant
Now let me look at the
closeTabimplementation in the store to understand its behavior.Assistant
Let me look at the closeTab implementation in the terminals slice
Assistant
Now let me also check the
TabBarcomponent briefly to understand the flow.Assistant
Now I have a good understanding of the issues. Let me create a plan:
- Auto-create effect (lines 97-103): Replace the
tabs.lengthcheck with abootstrappedRefthat only auto-creates once per open session closeFloatingTab(lines 169-174): Check if closing the last tab, and if so, close the panel viaonOpenChange(false)closeOthers(lines 176-185): Read fresh state withuseAppStore.getState()instead of staletabscloseToRight(lines 187-198): Read fresh state and use tab-bar order instead of raw array order
Let me implement these changes
- Auto-create effect (lines 97-103): Replace the
Assistant
Now let me apply the fixes. Starting with the auto-create effect:
Fix 1: Replace the auto-create effect with a bootstrap ref
Assistant
Now fix
closeFloatingTabto close the panel when the last tab is removed by user:Assistant
Now fix
closeOthersto useuseAppStore.getState()instead of stale `tabsAssistant
Let me view the full file to verify everything looks correct
Assistant
Let me now check if there are any tests related to the FloatingTerminalPanel that I can
Assistant
Let me verify the changes look good by checking the diff
Assistant
The changes look correct. Let me now verify the project builds without TypeScript errors
Assistant
Let me run the TypeScript type checker to ensure the changes compile correctly
Assistant
Let me try running the relevant tests instead
Assistant
Good, the store tests pass. Let me now also confirm our logic is sound by reviewing the full modified file once more, focusing on the key sections.
Assistant
Let me verify the changes are complete and correct by reviewing the full modified areas one more time
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.