Skip to content

fix(tabs): resolve document tab close by id or entityId (#16205) - #16480

Closed
BorjaLL wants to merge 1 commit into
stablyai:mainfrom
BorjaLL:BorjaLL/fix-close-document-tab
Closed

BorjaLL wants to merge 1 commit into
stablyai:mainfrom
BorjaLL:BorjaLL/fix-close-document-tab

Conversation

@BorjaLL

@BorjaLL BorjaLL commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Closing a Markdown/HTML document tab (its X button, the context-menu Close, or Cmd+W) could silently do nothing, so duplicate tabs piled up. This makes document tabs close reliably.

What Changed

In TabGroupPanel.tsx, every close handler for the unified-tab strip resolves the incoming id through resolveGroupTabFromVisibleId(model.groupTabs, visibleId), which matches either the unified tab's own id or its entityId (the tab bar emits entityId for terminals/browsers but the unified id for editors). onCloseFile - the handler behind a document tab's X, the context-menu Close, and Cmd+W - was the one exception: it was bound directly to commands.closeItem, a strict groupTabs.find(t => t.id === itemId) with no entityId fallback. When that path is fed the file's entityId, the strict match fails and the callback silently returns (no error, no toast) - exactly the reported symptom.

Fix: wrap onCloseFile with the same resolveGroupTabFromVisibleId resolution its sibling close handlers already use.

Why

The close wiring had a single id-resolution asymmetry; aligning onCloseFile with its siblings removes the silent no-op and the duplicate-tab pileup, with no behavior change for the paths that already worked.

Linked Issue

Fixes #16205

Visual Proof

N/A for static screenshots (the bug is a no-op). Repro: open a Markdown/HTML doc tab, trigger Close via the X / context menu / Cmd+W in a state where the file's entityId is emitted; before, the tab stays and re-opening stacks duplicates; after, it closes.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New TabGroupPanel.close-file-entity-id.test.ts: mounts the real TabGroupPanel against a real Zustand store, opens a markdown file, drives onCloseFile with the file's entityId. Fails before the fix, passes after.

  • pnpm vitest run on tab-bar + tab-group + close-lifecycle dirs: 522/522 pass. pnpm typecheck exit 0.

AI Disclosure

Implemented with Claude Code (Anthropic; Claude Sonnet). Root-cause analysis, the fix, and the tests were AI-generated and human-reviewed before opening.

Review

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer source, tests, fixtures, or docs are copied or translated.

Notes

Investigated a possible link to #16225 (mirrored tab-id normalization) and found it separate: that is a terminal-surface-id prefix scheme; mirrored editor tabs use the host's raw tab id directly. This fix is local to the tab-close id-resolution contract.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered (or N/A)
  • pnpm typecheck, pnpm test pass locally (CI covers build)

Author

  • X / Twitter: @bo_ns_ai

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TabGroupPanel now resolves a file entity ID to its matching unified tab before calling commands.closeItem. The handler skips closure when no matching tab exists. A Vitest regression test opens a document, invokes the handler with its entity ID, and verifies that both the unified tab and open-file entry are removed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description covers the required sections, explains the fix and rationale, links issue #16205, provides visual-proof justification, documents automated testing, and completes the relevant checklist…
Title check ✅ Passed The title clearly and concisely describes the primary change: resolving document tab closure by either the tab id or entityId.
Full details: Description check

Explanation

The description covers the required sections, explains the fix and rationale, links issue #16205, provides visual-proof justification, documents automated testing, and completes the relevant checklist items. Manual testing is unchecked, but this is non-critical because automated validation is documented.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/tab-group/TabGroupPanel.close-file-entity-id.test.ts (1)

3-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the regression comment.

Keep the issue ID and the entityId condition. The test name and assertions already define the failure and expected result.

Suggested change
-// Regression for `#16205`: a document (editor) tab's X button / "Close" menu item /
-// Cmd+W silently no-oped. TabGroupPanel wired onCloseFile straight to
-// commands.closeItem, which only matches a unified tab by its own id
-// (groupTabs.find(candidate => candidate.id === itemId)) — unlike every sibling
-// close handler in this file (onClose, onCloseOthers, onCloseToRight,
-// onCloseToLeft, onCloseBrowserTab), which all resolve the incoming id through
-// resolveGroupTabFromVisibleId first, because callers can emit either the
-// unified tab id or the file's entityId. This test drives onCloseFile with the
-// file's entityId (the shape a file-explorer/palette close path emits) and
-// asserts the tab actually closes.
+// Regression for `#16205`: close a document tab when the caller emits its entityId.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a6f49da2-bb62-42b5-8123-ed83aa987655

📥 Commits

Reviewing files that changed from the base of the PR and between bc98655 and c7b65a1.

📒 Files selected for processing (2)
  • src/renderer/src/components/tab-group/TabGroupPanel.close-file-entity-id.test.ts
  • src/renderer/src/components/tab-group/TabGroupPanel.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@BorjaLL

BorjaLL commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #25509, which covers this close path with stricter ownership checks. Thanks @nwparker for reviewing it there.

@BorjaLL BorjaLL closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Document tabs (md/html) cannot be closed — close actions are silent no-ops, duplicate tabs pile up

1 participant