@devries-cameron20 / t3code-1 / commits / 6fc2fb192c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): desktop browser tabs show native navigation immediately (#35299)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

rafi-the-dev committed Nov 14, 2026 at 19:12 UTC 6fc2fb192c95dd0ae06e962b06217206884987ec
7 files changed +115 -29
apps/web/src/components/preview/PreviewView.browser.test.tsx
+30 -2
@@ -31,6 +31,8 @@ const mocks = vi.hoisted(() => ({
31 pictureInPicture: false,
32 showEmptyState: false,
33 idleServerTab: false,
34 + idleDesktopTab: false,
35 + idleDesktopOverlay: false,
36 loading: false,
37 nativeServerTab: false,
38 streamedServerTab: false,
@@ -103,6 +105,9 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
105 desktopByTabId: {
106 "tab-1": {
107 hasWebContents: true,
108 + navStatus: mocks.idleDesktopOverlay
109 + ? { _tag: "Idle" }
110 + : { _tag: "Success", url: "http://example.com/", title: "Example" },
111 canGoBack: false,
112 canGoForward: false,
113 loading: mocks.loading,
@@ -117,12 +122,12 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
122 recentlySeenUrls: [],
123 sessions: mocks.showEmptyState
124 ? {}
120 - : mocks.idleServerTab
125 + : mocks.idleServerTab || mocks.idleDesktopTab
126 ? {
127 "tab-1": {
128 threadId: "thread-1",
129 tabId: "tab-1",
125 - runtime: "server",
130 + runtime: mocks.idleDesktopTab ? "desktop" : "server",
131 navStatus: { _tag: "Idle" },
132 canGoBack: false,
133 canGoForward: false,
@@ -228,6 +233,8 @@ function setup() {
233 mocks.pictureInPicture = false;
234 mocks.showEmptyState = false;
235 mocks.idleServerTab = false;
236 + mocks.idleDesktopTab = false;
237 + mocks.idleDesktopOverlay = false;
238 mocks.loading = false;
239 mocks.nativeServerTab = false;
240 mocks.streamedServerTab = false;
@@ -261,6 +268,27 @@ describe("PreviewView", () => {
268 },
269 );
270
271 + it("shows a desktop navigation before its backend status echo arrives", async () => {
272 + setup();
273 + mocks.idleDesktopTab = true;
274 + await using _screen = await render(view());
275 + await expect
276 + .element(page.getByPlaceholder("Search or enter URL"))
277 + .toHaveValue("http://example.com/");
278 + await expect.element(page.getByText("No preview yet")).not.toBeInTheDocument();
279 + await expect.element(page.getByRole("button", { name: "Annotate preview" })).toBeVisible();
280 + });
281 +
282 + it("keeps the server navigation while the new desktop tab is still idle", async () => {
283 + setup();
284 + mocks.idleDesktopOverlay = true;
285 + await using _screen = await render(view());
286 + await expect
287 + .element(page.getByPlaceholder("Search or enter URL"))
288 + .toHaveValue("http://example.com/");
289 + await expect.element(page.getByText("No preview yet")).not.toBeInTheDocument();
290 + });
291 +
292 it("keeps the address in the bar when Enter commits an IME composition", async () => {
293 setup();
294 await using _screen = await render(view());
apps/web/src/components/preview/PreviewView.tsx
+7 -3
@@ -81,7 +81,6 @@ import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
81 import { isBrowserSettingsReadError } from "~/browser/openFileInPreview";
82 import { PreviewFileNotShown, PreviewUnreachable } from "./PreviewUnreachable";
83 import { revealInFileExplorerLabel } from "./fileExplorerLabel";
84 -import { shouldShowPreviewEmptyState } from "./previewEmptyStateLogic";
84 import { Badge } from "~/components/ui/badge";
85 import { BrowserSurfaceSlot } from "~/browser/BrowserSurfaceSlot";
86 import { alternatePreviewRuntime, useRendersServerTabNatively } from "~/browser/previewRuntime";
@@ -234,14 +233,19 @@ export function PreviewView({
233 const desktopOverlay =
234 tabId && !isServerTab ? (previewState.desktopByTabId[tabId] ?? null) : null;
235 const layoutZoomFactor = useBrowserLayoutZoomFactor(desktopOverlay?.zoomFactor ?? 1);
237 - const navStatus = snapshot?.navStatus ?? { _tag: "Idle" as const };
236 + // A new Electron tab is Idle until its first URL commits, while the server already has it Loading.
237 + const desktopNavStatus =
238 + !serverOwnsRendering && desktopOverlay?.navStatus._tag !== "Idle"
239 + ? desktopOverlay?.navStatus
240 + : undefined;
241 + const navStatus = desktopNavStatus ?? snapshot?.navStatus ?? { _tag: "Idle" as const };
242 const url = navStatus._tag === "Idle" ? "" : navStatus.url;
243 const loading = desktopOverlay?.loading ?? navStatus._tag === "Loading";
244 const canGoBack = desktopOverlay?.canGoBack ?? snapshot?.canGoBack ?? false;
245 const canGoForward = desktopOverlay?.canGoForward ?? snapshot?.canGoForward ?? false;
246 const refreshDisabled = navStatus._tag === "Idle";
247 const isUnreachable = navStatus._tag === "LoadFailed";
244 - const showEmptyState = shouldShowPreviewEmptyState(snapshot);
248 + const showEmptyState = navStatus._tag === "Idle";
249 const serverStreamPending =
250 isServerTab && !showEmptyState && !isUnreachable && serverFrameTabId !== runtimeTabId;
251 const controller = desktopOverlay?.controller ?? "none";
apps/web/src/components/preview/previewEmptyStateLogic.ts
+1 -5
@@ -1,8 +1,4 @@
1 -import type { PreviewSessionSnapshot, ProjectScript } from "@t3tools/contracts";
2 -
3 -export function shouldShowPreviewEmptyState(snapshot: PreviewSessionSnapshot | null): boolean {
4 - return snapshot === null || snapshot.navStatus._tag === "Idle";
5 -}
1 +import type { ProjectScript } from "@t3tools/contracts";
2
3 export function getConfiguredPreviewUrls(
4 scripts: ReadonlyArray<ProjectScript> | undefined,
apps/web/src/components/preview/usePreviewBridge.test.ts
+20
@@ -66,6 +66,26 @@ describe("buildReportInput", () => {
66 });
67
68 describe("projectDesktopState", () => {
69 + it("keeps the native load failure details for the panel", () => {
70 + expect(
71 + projectDesktopState(
72 + state({
73 + kind: "LoadFailed",
74 + url: "https://example.com/",
75 + title: "",
76 + code: -105,
77 + description: "failed",
78 + }),
79 + ).navStatus,
80 + ).toEqual({
81 + _tag: "LoadFailed",
82 + url: "https://example.com/",
83 + title: "",
84 + code: -105,
85 + description: "failed",
86 + });
87 + });
88 +
89 it("shows a retained icon only while the current document has the captured origin", () => {
90 expect(
91 projectDesktopState(
apps/web/src/components/preview/usePreviewBridge.ts
+22 -18
@@ -1,6 +1,7 @@
1 import type {
2 DesktopPreviewTabState,
3 PreviewReportStatusInput,
4 + PreviewSessionSnapshot,
5 ScopedThreadRef,
6 ThreadId,
7 } from "@t3tools/contracts";
@@ -121,10 +122,30 @@ function shouldClearBrowserPointer(
122 return current.url !== previous.url;
123 }
124
125 +function projectDesktopNavStatus(
126 + status: DesktopPreviewTabState["navStatus"],
127 +): PreviewSessionSnapshot["navStatus"] {
128 + switch (status.kind) {
129 + case "Idle":
130 + return { _tag: "Idle" };
131 + case "LoadFailed":
132 + return {
133 + _tag: "LoadFailed",
134 + url: status.url,
135 + title: status.title,
136 + code: status.code,
137 + description: status.description,
138 + };
139 + default:
140 + return { _tag: status.kind, url: status.url, title: status.title };
141 + }
142 +}
143 +
144 export function projectDesktopState(state: DesktopPreviewTabState): DesktopPreviewOverlay {
145 const navOrigin = state.navStatus.kind === "Idle" ? null : originOf(state.navStatus.url);
146 return {
147 hasWebContents: state.webContentsId !== null,
148 + navStatus: projectDesktopNavStatus(state.navStatus),
149 canGoBack: state.canGoBack,
150 canGoForward: state.canGoForward,
151 loading: state.navStatus.kind === "Loading",
@@ -168,27 +189,10 @@ export function buildReportInput(args: {
189 canGoBack: state.canGoBack,
190 canGoForward: state.canGoForward,
191 };
171 - if (status.kind === "LoadFailed") {
172 - return {
173 - input: {
174 - ...base,
175 - navStatus: {
176 - _tag: "LoadFailed",
177 - url: status.url,
178 - title: status.title,
179 - code: status.code,
180 - description: status.description,
181 - },
182 - },
183 - lastReportedUrl: status.url,
184 - lastReportedKind: "LoadFailed",
185 - lastReportedTitle: status.title,
186 - };
187 - }
192 return {
193 input: {
194 ...base,
191 - navStatus: { _tag: status.kind, url: status.url, title: status.title },
195 + navStatus: projectDesktopNavStatus(status),
196 },
197 lastReportedUrl: status.url,
198 lastReportedKind: status.kind,
apps/web/src/previewStateStore.test.ts
+18 -1
@@ -172,6 +172,7 @@ describe("previewStateStore (single-tab)", () => {
172 applyPreviewServerSnapshot(ref, snapshot);
173 const overlay = {
174 hasWebContents: true,
175 + navStatus: { _tag: "Idle" as const },
176 canGoBack: true,
177 canGoForward: false,
178 loading: false,
@@ -194,9 +195,22 @@ describe("previewStateStore (single-tab)", () => {
195
196 applyPreviewDesktopState(ref, snapshot.tabId, overlay);
197 applyPreviewDesktopState(ref, snapshot.tabId, { ...overlay, favicon: { ...overlay.favicon } });
198 + const loaded = {
199 + ...overlay,
200 + navStatus: { _tag: "Success" as const, url: "https://example.com/", title: "Example" },
201 + };
202 + applyPreviewDesktopState(ref, snapshot.tabId, loaded);
203 + applyPreviewDesktopState(ref, snapshot.tabId, {
204 + ...loaded,
205 + navStatus: { ...loaded.navStatus },
206 + });
207 + applyPreviewDesktopState(ref, snapshot.tabId, {
208 + ...loaded,
209 + navStatus: { ...loaded.navStatus, url: "https://example.com/next" },
210 + });
211 unsubscribe();
212
199 - expect(updateCount).toBe(1);
213 + expect(updateCount).toBe(3);
214 });
215
216 it("retains multiple tabs and switches active desktop state", () => {
@@ -206,6 +220,7 @@ describe("previewStateStore (single-tab)", () => {
220 applyPreviewServerSnapshot(ref, second);
221 applyPreviewDesktopState(ref, first.tabId, {
222 hasWebContents: true,
223 + navStatus: { _tag: "Idle" as const },
224 canGoBack: true,
225 canGoForward: false,
226 loading: false,
@@ -235,6 +250,7 @@ describe("previewStateStore (single-tab)", () => {
250 applyPreviewServerSnapshot(ref, active);
251 applyPreviewDesktopState(ref, stale.tabId, {
252 hasWebContents: true,
253 + navStatus: { _tag: "Idle" as const },
254 canGoBack: false,
255 canGoForward: false,
256 loading: false,
@@ -366,6 +382,7 @@ describe("previewStateStore (single-tab)", () => {
382 beginPreviewSessionClose(ref, previous.tabId);
383 applyPreviewDesktopState(ref, previous.tabId, {
384 hasWebContents: true,
385 + navStatus: { _tag: "Idle" as const },
386 canGoBack: false,
387 canGoForward: false,
388 loading: false,
apps/web/src/previewStateStore.ts
+17
@@ -15,6 +15,7 @@ import { appAtomRegistry } from "./rpc/atomRegistry";
15
16 export interface DesktopPreviewOverlay {
17 hasWebContents: boolean;
18 + navStatus: PreviewSessionSnapshot["navStatus"];
19 canGoBack: boolean;
20 canGoForward: boolean;
21 loading: boolean;
@@ -375,6 +376,21 @@ function haveSameValues<T>(left: Record<string, T>, right: Record<string, T>): b
376 return keys.length === Object.keys(right).length && keys.every((key) => left[key] === right[key]);
377 }
378
379 +function sameDesktopNavStatus(
380 + previous: DesktopPreviewOverlay["navStatus"],
381 + next: DesktopPreviewOverlay["navStatus"],
382 +): boolean {
383 + if (previous._tag === "Idle" || next._tag === "Idle") return previous._tag === next._tag;
384 + return (
385 + previous._tag === next._tag &&
386 + previous.url === next.url &&
387 + previous.title === next.title &&
388 + (previous._tag !== "LoadFailed" ||
389 + next._tag !== "LoadFailed" ||
390 + (previous.code === next.code && previous.description === next.description))
391 + );
392 +}
393 +
394 function isPreviewStateEqual(
395 previous: DesktopPreviewOverlay | null,
396 next: DesktopPreviewOverlay | null,
@@ -384,6 +400,7 @@ function isPreviewStateEqual(
400 (previous !== null &&
401 next !== null &&
402 previous.hasWebContents === next.hasWebContents &&
403 + sameDesktopNavStatus(previous.navStatus, next.navStatus) &&
404 previous.canGoBack === next.canGoBack &&
405 previous.canGoForward === next.canGoForward &&
406 previous.loading === next.loading &&