Skip to content

Commit f697d4d

Browse files
fix(web): local server cards in the browser empty state take pointer clicks (#34050)
1 parent a536ff7 commit f697d4d

2 files changed

Lines changed: 60 additions & 15 deletions

File tree

‎apps/web/src/components/preview/PreviewView.browser.test.tsx‎

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const mocks = vi.hoisted(() => ({
3030
addImage: vi.fn(),
3131
pictureInPicture: false,
3232
showEmptyState: false,
33+
idleServerTab: false,
3334
loading: false,
3435
nativeServerTab: false,
3536
serverEpoch: null as string | null,
@@ -112,17 +113,29 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
112113
recentlySeenUrls: [],
113114
sessions: mocks.showEmptyState
114115
? {}
115-
: {
116-
"tab-1": {
117-
threadId: "thread-1",
118-
tabId: "tab-1",
119-
runtime: mocks.nativeServerTab ? "server" : "desktop",
120-
navStatus: { _tag: "Success", url: "http://example.com/", title: "Example" },
121-
canGoBack: false,
122-
canGoForward: false,
123-
updatedAt: "2026-07-13T00:00:00.000Z",
116+
: mocks.idleServerTab
117+
? {
118+
"tab-1": {
119+
threadId: "thread-1",
120+
tabId: "tab-1",
121+
runtime: "server",
122+
navStatus: { _tag: "Idle" },
123+
canGoBack: false,
124+
canGoForward: false,
125+
updatedAt: "2026-07-13T00:00:00.000Z",
126+
},
127+
}
128+
: {
129+
"tab-1": {
130+
threadId: "thread-1",
131+
tabId: "tab-1",
132+
runtime: mocks.nativeServerTab ? "server" : "desktop",
133+
navStatus: { _tag: "Success", url: "http://example.com/", title: "Example" },
134+
canGoBack: false,
135+
canGoForward: false,
136+
updatedAt: "2026-07-13T00:00:00.000Z",
137+
},
124138
},
125-
},
126139
})) as never,
127140
}));
128141
vi.mock(import("~/state/environments"), async (original) => ({
@@ -151,6 +164,13 @@ vi.mock(import("~/browser/previewRuntime"), async (original) => ({
151164
}));
152165

153166
vi.mock(import("~/browser/browserViewportActions"), { spy: true });
167+
// The real surface opens a preview stream to the server; only its box matters here.
168+
vi.mock(import("~/browser/ServerBrowserSurface"), async (original) => ({
169+
...(await original()),
170+
ServerBrowserSurface: ((props: { className?: string }) => (
171+
<div data-testid="server-browser-surface" className={props.className} />
172+
)) as never,
173+
}));
154174

155175
import { useComposerDraftStore } from "~/composerDraftStore";
156176
import { useBrowserPointerStore } from "~/browser/browserPointerStore";
@@ -201,6 +221,7 @@ function setup() {
201221
mocks.pickElement.mockReset();
202222
mocks.pictureInPicture = false;
203223
mocks.showEmptyState = false;
224+
mocks.idleServerTab = false;
204225
mocks.loading = false;
205226
mocks.nativeServerTab = false;
206227
mocks.serverEpoch = null;
@@ -287,6 +308,30 @@ describe("PreviewView", () => {
287308
expect(mocks.addImage).not.toHaveBeenCalled();
288309
});
289310

311+
it("lets the pointer reach a local server card above an idle server-rendered tab", async () => {
312+
setup();
313+
mocks.idleServerTab = true;
314+
mocks.servers = [
315+
{
316+
host: "localhost",
317+
port: 8081,
318+
url: "http://localhost:8081/",
319+
requestedUrl: "http://localhost:8081/",
320+
processName: "python3",
321+
pid: 4242,
322+
terminal: null,
323+
source: "scanner",
324+
},
325+
];
326+
await using _screen = await render(<ToastProvider timeout={0}>{view()}</ToastProvider>);
327+
const card = page.getByRole("button", { name: /localhost:8081/ });
328+
await expect.element(card).toBeVisible();
329+
330+
const rect = card.element().getBoundingClientRect();
331+
const hit = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
332+
expect(card.element().contains(hit)).toBe(true);
333+
});
334+
290335
it("focuses and selects the address from forwarded desktop actions only while visible", async () => {
291336
setup();
292337
using stack = new DisposableStack();

‎apps/web/src/components/preview/PreviewView.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,10 @@ export function PreviewView({
991991
</div>
992992
) : null}
993993
<div
994-
className="absolute inset-x-0 bottom-0"
994+
className={cn(
995+
"absolute inset-x-0 bottom-0",
996+
(showEmptyState || isUnreachable) && "invisible",
997+
)}
995998
style={{ top: viewport._tag !== "fill" ? BROWSER_DEVICE_TOOLBAR_HEIGHT : 0 }}
996999
>
9971000
<ServerBrowserSurface
@@ -1012,10 +1015,7 @@ export function PreviewView({
10121015
}
10131016
onPopup={(popupTabId) => showPreviewPopup(threadRef, popupTabId, "panel")}
10141017
// Stays connected under the empty state so a URL picked there reaches the page.
1015-
className={cn(
1016-
"absolute inset-0 h-full w-full",
1017-
(showEmptyState || isUnreachable) && "invisible",
1018-
)}
1018+
className="absolute inset-0 h-full w-full"
10191019
/>
10201020
</div>
10211021
</>

0 commit comments

Comments
 (0)