Skip to content

Restore previously-active tab when closing a browser tab - #16306

Merged
AmethystLiang merged 2 commits into
mainfrom
closing-a-browser-tab-should-go-back-to-previously-active-tab
Aug 24, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
closing-a-browser-tab-should-go-back-to-previously-active-tab

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​121 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​117
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

Problem

When closing a browser tab, Orca switches to the next tab in visual order (right neighbor, or left if none). This ignores user context — they want to return to what they were working on before, not just the adjacent tab.

Solution

Changed tab-close behavior to restore the previously-active (MRU) tab instead of picking a visual neighbor. This respects the actual usage pattern and works across content types (browser, terminal, editor tabs tracked together in the unified system).

What Changed

browser.ts: Improved next-tab selection when closing a browser tab. Uses pickNeighbor() to find a candidate, but validates it still exists; falls back to the first remaining tab. Fixed global activeBrowserTabId to use the pre-computed worktree-specific selection instead of recalculating.

Terminal.tsx: Removed the inline tab-switching logic that was picking neighbors. Moved responsibility to the store via MRU tracking. When closing the last browser tab in a worktree, checks if it's wrapped in the unified tab system before falling back to a file tab.

Tests: Added 4 new tests for MRU restoration:

  • MRU selection when closing active browser tab in active worktree
  • Keeping unified MRU target when closing the last browser tab (switches to previous terminal/editor tab)
  • Proper selection for inactive worktrees
  • Legacy tab handling without unified wrapper

Updated existing test to verify MRU works across content types (terminal → browser → editor), not just visual neighbors.

Visual Proof

N/A — interaction change verified by unit tests. Manual verification: open 3+ browser tabs, activate tab A, activate tab B, close tab B → should return to tab A (not the visual neighbor).

Testing

  • Automated tests added/updated
    • New MRU selection tests for various scenarios
    • Updated existing tab-close test to verify cross-content-type MRU
    • Covers active/inactive worktree cases and legacy (non-unified) tab handling

Cross-platform Impact

No platform-specific behavior added. Logic is generic tab management, applicable to macOS, Linux, Windows, and SSH.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Closing a browser tab now activates the most-recently-used (MRU)
tab instead of the visual neighbor. This provides more predictable
navigation behavior when switching between tabs.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b660d6fa-1e2f-413d-87c4-27fbd96668fa

📥 Commits

Reviewing files that changed from the base of the PR and between 89545ce and f9b5691.

📒 Files selected for processing (5)
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/floating-terminal/FloatingTerminalPanel.tsx
  • src/renderer/src/components/tab-group/useTabGroupTabCloseCommands.ts
  • src/renderer/src/store/slices/browser.test.ts
  • src/renderer/src/store/slices/browser.ts

📝 Walkthrough

Walkthrough

Browser tab closure now validates the remaining target and updates the browser bridge before webview destruction. Terminal, floating-terminal, and tab-group close paths now close browser tabs before destroying workspace webviews. Tests cover unified MRU selection, last-browser-tab fallback, inactive worktrees, legacy browser tabs, active-page notification, and mixed content types.

🚥 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 1 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: restoring the previously active tab after closing a browser tab.
Description check ✅ Passed The description clearly explains the problem, solution, implementation, visual proof, and automated tests, but it omits the required linked issue.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

When closing a browser tab, announce the MRU page selection
before guest teardown to prevent fallback to registration order.
Reorder closeBrowserTab() before destroyWorkspaceWebviews()
consistently across all close-tab handlers.
@AmethystLiang
AmethystLiang merged commit 0c4dd2b into main Aug 24, 2026
2 of 16 checks passed
Jinwoo-H added a commit that referenced this pull request Aug 25, 2026
Main's module-split refactors moved most of the conflicted code out from under
this branch, so several edits had to be relocated rather than merged in place.

Conflicts and how each was resolved:

.github/workflows/pr.yml
  Main replaced the inline shell spec routing with config/scripts/pr-e2e-source-routing.mjs.
  Ported both client-hosted-browser routes into that script as
  client-hosted-browser.host-strip and client-hosted-browser.restart-survival, and rewired
  pr-e2e-gate-contract.test.mjs to read the restart-survival route from PR_E2E_SOURCE_ROUTES
  instead of scraping the workflow shell that no longer exists. Windows boundary test list is
  a union of both sides.

src/main/global-fetch-call-site-audit.test.ts
  Union, minus a stale entry: main moved the audited fetch out of opencode/hook-service.ts into
  status-plugin-post-source.ts, so main's replacement wins and our browser-route entries stay.

src/main/persistence/loading-store/store.ts
  Took main's file wholesale. Our only delta was the runtime-authored guard, which relocated to
  main's new chokepoints: preserveRuntimeAuthoredWorkspaceSessionFields now runs at the top of
  setLocalWorkspaceSession (loading-store/workspace-session-snapshot-publication.ts) and
  setHostWorkspaceSession (loading-store/session-host-partitions.ts). Censused every writer of
  state.workspaceSession / workspaceSessionsByHostId on both sides: the guarded and unguarded
  sets match pre-split coverage, and stageWorkspaceSessionBeforeUnload still inherits it.

src/main/persistence/restoring-sessions/session-owner-fields.ts
  Kept the census-driven delete loop and main's new host-identity-aware scan for
  lastVisitedAtByWorktreeId. That field is now excluded from the plain loop alongside
  terminalTopologyRevisionByRepoId, since it also carries `${executionHostId}|${worktreeId}`
  keys that indexing by owner key would miss. Updated the pinned census list and added explicit
  coverage for the bare-vs-host-qualified delete that left the it.each loop.

src/main/runtime/orca-runtime.ts
  Import-block conflict only; merged main's widened runtime-browser-commands-factory import with
  ours. Verified all 495 added lines from this branch survived the body auto-merge, including
  persistClientHostedBrowserPages, rehydrateClientHostedBrowserPages, the boolean-returning
  retireRuntimeOwnedBrowserSessionTab, and the ghost-row retirement ordering.

src/main/window/createMainWindow.ts
  Main split this into main-window-*-lifecycle modules. The browser-host-id argv stamp stays with
  the BrowserWindow construction; the will-attach-webview partition allowlist and did-attach-webview
  guest policies moved to main-window-webview-security.ts; registerRendererDocumentNavigation and
  the client-page attach/retire wiring moved to main-window-focus-lifecycle.ts. The privileged
  navigation policy and plugin panel guard stayed in main's module: neither ordering this branch
  established is load-bearing (the guard only handles subframes, the fence reads defaultPrevented
  in a microtask). createMainWindow.test.ts now records every handler per event instead of the
  last one, because two modules register will-navigate on the same webContents.

src/main/wsl/__fixtures__/wsl-invocation-allowlist.txt
  Union, minus a stale entry: main moved the wsl.exe invocation out of claude-accounts/service.ts
  into claude-command-process.ts.

src/renderer/src/components/Terminal.tsx
  Combined main's #16306 MRU close with our plan-driven close options: closeBrowserTab now runs
  before destroyWorkspaceWebviews at all three sites and keeps the plan's reason, main's
  hasUnifiedEntry guard is kept, and the visual-neighbor selection main deleted stays deleted
  because closeBrowserTab picks the MRU target itself. All browser-guest-paint-retention helpers
  remain wired at their sites.

src/renderer/src/components/tab-group/useTabGroupTabCloseCommands.ts
  Kept our closeBrowserItem plan helper and carried main's #16306 ordering into it. Applied the
  same flip in runtime/browser-workspace-tab-close.ts, a close-tab handler this branch added
  after main's commit and which main could not reach.

src/renderer/src/hooks/useIpcEvents.ts
  Main reduced this to a shim over ipc-events/app-lifetime-ipc-bridge. Relocated all five edits:
  the client-hosted certificate-failure carve-out to ipc-events/browser-state-ipc-bridge.ts, the
  paired-device create comment to browser-request-ipc-bridge.ts, the plan-routed menu close to
  tab-lifecycle-ipc-bridge.ts, and the browser-remote-viewer plus client-hosted-row channels and
  their hydration to mobile-driver-ipc-bridge.ts. Added both channels to main's new
  useIpcEvents-lifecycle.test.ts callback census.

src/renderer/src/web/web-preload-api.ts
  Main split this into web/preload-api/*. Relocated the web-client no-op stubs into
  web-runtime-api.ts, web-runtime-environments-api.ts, and web-browser-api.ts.

Integration fixes outside the conflicts: main's new orcad test fixtures and
external-chromium-tab-registry.ts predate this branch's RuntimeBrowserCommandHost members and
BrowserSessionTabSelectionOptions, so the fixtures gained the four registry accessors and the
external-Chromium create now passes an options object with focusesHost: true, preserving the
always-steer behavior that call had before create learned to stay local.

The renderer close-site census in runtime/browser-workspace-tab-close-census.test.ts was
repointed at the three ipc-events modules that now hold useIpcEvents.ts's seven closeBrowserTab
mentions (tab-lifecycle 2 plan-routed, browser-request 3 and session-tab 2 host-requested).

No wire changes: no RPC params or stream frames were touched by any conflict.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
)

* Restore previously-active tab when closing a browser tab

Closing a browser tab now activates the most-recently-used (MRU)
tab instead of the visual neighbor. This provides more predictable
navigation behavior when switching between tabs.

* Restore previously-active tab when closing a browser tab

When closing a browser tab, announce the MRU page selection
before guest teardown to prevent fallback to registration order.
Reorder closeBrowserTab() before destroyWorkspaceWebviews()
consistently across all close-tab handlers.

(cherry picked from commit 0c4dd2b)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
)

* Restore previously-active tab when closing a browser tab

Closing a browser tab now activates the most-recently-used (MRU)
tab instead of the visual neighbor. This provides more predictable
navigation behavior when switching between tabs.

* Restore previously-active tab when closing a browser tab

When closing a browser tab, announce the MRU page selection
before guest teardown to prevent fallback to registration order.
Reorder closeBrowserTab() before destroyWorkspaceWebviews()
consistently across all close-tab handlers.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* Restore previously-active tab when closing a browser tab

Closing a browser tab now activates the most-recently-used (MRU)
tab instead of the visual neighbor. This provides more predictable
navigation behavior when switching between tabs.

* Restore previously-active tab when closing a browser tab

When closing a browser tab, announce the MRU page selection
before guest teardown to prevent fallback to registration order.
Reorder closeBrowserTab() before destroyWorkspaceWebviews()
consistently across all close-tab handlers.
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.

1 participant