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
Good, this gives a clear pattern to follow. Now let's implement the fix in FloatingTerminalPanel.tsx.
Assistant
Now let's add the import for
reconcileTabOrderand update the bootstrap effect.Assistant
Now let's update the bootstrap effect. Let's view exact lines around it.
Assistant
Now add a ref to track prior open state, and rewrite the bootstrap effect.
Assistant
Now replace the bootstrap effect body (lines 105-111).
Assistant
Now let's update
closeFloatingTab,closeOthers,closeToRight.Assistant
Let me use
editwith line ranges directly instead.Assistant
There's a leftover extra
)on line 245. Let's remove it.Assistant
Now missing blank line before
toggleMaximized. Let's add it back for style consistency.Assistant
Now let's update the
onCloseTabprop ofTerminalPaneto usecloseFloatingTabinstead of rawcloseTab, while keepingonPtyExitas rawcloseTab.Assistant
Now let's view the whole file for sanity, then typecheck with tsc.
Assistant
Now let's check TypeScript compiles for this file, and run relevant lints/tests.
Assistant
Typecheck passes. Now run lint on this file.
Assistant
Now let's write a quick script/test to verify behavior logically. Let's check if there are existing tests for this component that use React Testing Library, to see if we can add a temp test to verify (without committing it).
Assistant
Good, this gives everything needed. Let me create a temporary test harness reusing this pattern, but importing the actual
useAppStoreand replicating the panel's callback logic to validate against real store behavior.Assistant
All 4 tests pass, validating the exact logic implemented in the component. Now let's remove the temp test file.
Assistant
Good, only the intended file is modified. Now let's run the full existing test suite for related areas to confirm nothing broke.
Assistant
All existing related tests pass (stderr output is expected console.error from an intentional error-path test, not a failure). Now let's run the full test suite and lint/typecheck once more for confidence.
Assistant
Confirmed: identical baseline failure counts (47 failed test files, 75 failed tests) with and without my change — these are pre-existing environment issues (missing native modules), not caused by my fix. Now let's do a final review of the diff.
Assistant
This diff looks clean and focused. Let's do a final typecheck and lint pass to be safe.
Assistant
Everything passes cleanly. Let's go through the checklist.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.