fix(preview): browser tabs no longer go blank when the tab list reorders #13799
main fromrefs/pull/13799/head·merged by juliusmarminge View on GitHubTakes over #13799 by @mkiera, who diagnosed the cause with a standalone Electron script and proposed the stable order. Rebuilt on current main. Fixes #13798.
Problem#
ElectronBrowserHost renders one <webview> per preview tab, across every thread, in the order the sessions come out of the preview store. preview.list sorts tabs by updatedAt, and a list reload rebuilds the client's session map in that order. When a tab opened earlier becomes the most recently updated, the next reload reverses the order and React moves that tab's <webview> element. Electron destroys a webview's guest when its element leaves the DOM and does not attach a new one on insert. The tab shows a white page, the desktop reports it unavailable with url: null, and automation on it waits out its 15 second deadline.
Change#
apps/web/src/browser/ElectronBrowserHost.tsx sorts the sessions by runtime tab id before rendering, with a plain string comparison so the order is the same on every machine. An existing webview keeps its DOM position when tabs are added, removed, or reordered, including across threads. The order is only fixed, not meaningful: stacking uses explicit z-indexes, the link handler looks tabs up by id, and the store keeps its recency order for the browser panel.
Compared with the original PR: the useMemo wrapper is gone (main dropped it), localeCompare became a plain comparison, and the react-test-renderer test (a dependency this repo does not have) is replaced by a browser test.
Verification#
New apps/web/src/browser/ElectronBrowserHost.browser.test.tsx (Playwright): renders the host with two server tabs, reloads them in reverse updatedAt order, and asserts with a MutationObserver that no node under the host was removed and that the two <webview> elements are the same nodes in the same order.
Before, with ElectronBrowserHost.tsx from main:
× never moves a tab's webview when the server reorders tabs by last update
AssertionError: expected [ <div …(4)>…(1)</div> ] to deeply equal []
After:
Test Files 1 passed (1)
Tests 1 passed (1)
apps/web typecheck: exit 0. Lint and format on both files: clean. Two independent adversarial review rounds (Claude Opus 5.5 and GPT-6-Sol) found no blocking issues.
Not verified: a live Electron desktop build; this machine is headless Linux, so the proof is the browser test above and the original author's Windows reproduction. No UI change, so screenshots do not apply. Web and mobile are unaffected because hosted webviews exist only in Electron.
Done by Claude Fable 5.1 in Claude Code, run from T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
188bc0dMacroscope's review found this PR approvable — The PR makes a focused Electron webview ordering fix that prevents existing browser tabs from being detached when server tab recency changes. Its accompanying browser regression test is harness-only, and no defaults, static-analysis suppressions, schemas, or sensitive packages are modified.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 5 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
844e6638-2cdd-4509-a8c4-4af1d37ad560
📥 Commits
-
Reviewing files that changed from the base of the PR and between 6325f8c2f54e3d1e7ed2e77687f3acd8cfa92133 and 188bc0d28e6376c1a4ef1e44a180deacb329dfba.
📒 Files selected for processing: 2
-
apps/web/src/browser/ElectronBrowserHost.browser.test.tsxapps/web/src/browser/ElectronBrowserHost.tsx
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
44cd2161-e2a3-4365-99c3-6273d3a13fa6
📥 Commits
-
Reviewing files that changed from the base of the PR and between 2679d279ce4b4879290bc756cf219b10f77e1873 and 6325f8c2f54e3d1e7ed2e77687f3acd8cfa92133.
📒 Files selected for processing (2)
-
apps/web/src/browser/ElectronBrowserHost.test.tsxapps/web/src/browser/ElectronBrowserHost.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
ElectronBrowserHost sorts valid preview sessions by runtimeTabId. A regression test checks that the rendered tab order remains unchanged when a later server revision returns the sessions in reversed order.
Changes: Preview tab ordering
Layer / File(s) Summary Sort sessions and verify rendered order
apps/web/src/browser/ElectronBrowserHost.tsx,apps/web/src/browser/ElectronBrowserHost.test.tsxElectronBrowserHost sorts valid preview sessions by runtimeTabId. The test reconciles sessions in reversed order and checks that rendered tab order remains unchanged. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
6325f-
The change stabilizes preview tab order when session snapshots arrive reordered, and its test detects a regression in that behavior. No actionable merge risk remains.
Security architecture risk: 🔵 Low · up to
6325f-
The change stabilizes preview tabs during reordering without changing which tabs or profiles the host renders. No new access path was identified, though live Electron behavior is not established by the regression test alone.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The changed operation affects ordering within the existing desktop preview host; it does not add a session, expand thread selection, or change the identity used to key a webview.
Trust Boundaries and Controls
- inferred — No bypass of the existing preview identity boundary was identified: parsed thread identity and the environment-scoped runtime tab ID remain inputs to the same webview rendering path.
-
Pre-merge checks:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage 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 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 Issue [ #13798] requires tabs to retain usable pages when a refreshed list changes order.ElectronBrowserHostnow sorts sessions by stableruntimeTabIdbefore rendering and keeps that value as the …Out of Scope Changes check The pull request changes only ElectronBrowserHostrendering order and adds a focused regression test. The changes directly support issue [#13798]. No unrelated product behavior, platform, or UI chan…Title check The title clearly and concisely describes the primary fix: preventing browser tabs from going blank when preview tab order changes. Description check The description clearly documents the problem, root cause, implementation, verification results, limitations, and affected platforms. It does not include a separate Scope and approval section, but it … Full details: Linked Issues check
-
Explanation
Issue [
#13798] requires tabs to retain usable pages when a refreshed list changes order.ElectronBrowserHostnow sorts sessions by stableruntimeTabIdbefore rendering and keeps that value as theHostedBrowserWebviewkey. This prevents React from moving keyed webviews whenupdatedAtchanges.previewRuntimeTabIdincludes environment, thread, server epoch, and tab ID. The new test verifies that the rendered tab order remains unchanged after the server reverses the list order. These changes address the reported webview destruction and preserve tab usability.
Full details: Out of Scope Changes check
-
Explanation
The pull request changes only
ElectronBrowserHostrendering order and adds a focused regression test. The changes directly support issue [#13798]. No unrelated product behavior, platform, or UI changes appear in the reviewed diff.
Full details: Description check
-
Explanation
The description clearly documents the problem, root cause, implementation, verification results, limitations, and affected platforms. It does not include a separate Scope and approval section, but it links the related issue and prior PR, which provides sufficient scope context for this focused bug fix.
-
-
Comment `@coderabbitai help` to get the list of available commands.✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
-
juliusmarminge added labelsmacroscope-review
Taking over this one. I'll rebuild it on top of current main and push to this branch.
juliusmarminge assignedjuliusmarminge
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisfc5b621
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed