Skip to content

Commit 2983a03

Browse files
fix(web): keep replacement browser cursors visible during recording
1 parent 28dae3c commit 2983a03

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
FILL_PREVIEW_VIEWPORT,
88
ThreadId,
99
} from "@t3tools/contracts";
10-
import { act, Profiler } from "react";
10+
import { act, createElement, Profiler } from "react";
1111
import { renderToStaticMarkup } from "react-dom/server";
1212
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1313

@@ -33,6 +33,9 @@ const mocks = vi.hoisted(() => ({
3333
pictureInPicture: false,
3434
showEmptyState: false,
3535
loading: false,
36+
serverEpoch: null as string | null,
37+
recordingTabIds: new Set<string>(),
38+
recordingRuntimeTabId: null as string | null,
3639
recordVisitForThread: vi.fn(),
3740
}));
3841

@@ -98,6 +101,7 @@ vi.mock("~/previewStateStore", () => ({
98101
updatePreviewServerSnapshot: vi.fn(),
99102
useThreadPreviewState: () => ({
100103
activeTabId: "tab-1",
104+
serverEpoch: mocks.serverEpoch,
101105
desktopByTabId: {
102106
"tab-1": {
103107
hasWebContents: true,
@@ -146,11 +150,11 @@ vi.mock("~/state/use-atom-command", () => ({
146150
}));
147151

148152
vi.mock("~/browser/browserRecording", () => ({
149-
findActiveBrowserRecordingRuntimeTabId: vi.fn(() => null),
153+
findActiveBrowserRecordingRuntimeTabId: () => mocks.recordingRuntimeTabId,
150154
isBrowserRecordingStartCancelledError: vi.fn(() => false),
151155
startBrowserRecording: vi.fn(),
152156
stopBrowserRecording: vi.fn(),
153-
useActiveBrowserRecordingTabIds: () => new Set(),
157+
useActiveBrowserRecordingTabIds: () => mocks.recordingTabIds,
154158
}));
155159

156160
vi.mock("~/browser/browserSurfaceStore", () => ({
@@ -244,7 +248,9 @@ vi.mock("./PreviewMoreMenu", () => ({
244248
}));
245249
vi.mock("./PreviewUnreachable", () => ({ PreviewUnreachable: () => null }));
246250
vi.mock("./ZoomIndicator", () => ({ ZoomIndicator: () => null }));
247-
vi.mock("./AgentBrowserCursor", () => ({ AgentBrowserCursor: () => null }));
251+
vi.mock("./AgentBrowserCursor", () => ({
252+
AgentBrowserCursor: () => createElement("agent-cursor"),
253+
}));
248254
vi.mock("~/browser/BrowserSurfaceSlot", () => ({ BrowserSurfaceSlot: () => null }));
249255
vi.mock("./usePreviewSession", () => ({ usePreviewSession: vi.fn() }));
250256

@@ -344,9 +350,38 @@ describe("PreviewView navigation", () => {
344350
mocks.pictureInPicture = false;
345351
mocks.showEmptyState = false;
346352
mocks.loading = false;
353+
mocks.serverEpoch = null;
354+
mocks.recordingTabIds = new Set();
355+
mocks.recordingRuntimeTabId = null;
347356
mocks.recordVisitForThread.mockClear();
348357
});
349358

359+
it("shows the cursor in a replacement browser while the old instance still records", async () => {
360+
const document = installTestDom();
361+
const { createRoot } = await import("react-dom/client");
362+
const container = document.createElement("div");
363+
const root = createRoot(container as unknown as Element);
364+
const hasCursor = (node: TestNode): boolean =>
365+
node.nodeName === "AGENT-CURSOR" || node.childNodes.some(hasCursor);
366+
mocks.recordingTabIds.add(TEST_RUNTIME_TAB_ID);
367+
mocks.recordingRuntimeTabId = TEST_RUNTIME_TAB_ID;
368+
try {
369+
await act(() => {
370+
root.render(<PreviewView threadRef={TEST_THREAD_REF} tabId="tab-1" visible />);
371+
});
372+
expect(hasCursor(container)).toBe(false);
373+
mocks.serverEpoch = "replacement-server";
374+
await act(() => {
375+
root.render(<PreviewView threadRef={TEST_THREAD_REF} tabId="tab-1" visible />);
376+
});
377+
expect(hasCursor(container)).toBe(true);
378+
expect(mocks.recordingTabIds.has(TEST_RUNTIME_TAB_ID)).toBe(true);
379+
} finally {
380+
await act(() => root.unmount());
381+
vi.unstubAllGlobals();
382+
}
383+
});
384+
350385
it("does not rerender while loading time passes", async () => {
351386
vi.useFakeTimers();
352387
mocks.loading = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ export function PreviewView({
802802
desktopOverlay &&
803803
!showEmptyState &&
804804
!isUnreachable &&
805-
!recordingRuntimeTabId ? (
805+
!activeRecordingTabIds.has(runtimeTabId) ? (
806806
<AgentBrowserCursor
807807
tabId={runtimeTabId}
808808
zoomFactor={desktopOverlay.zoomFactor}

0 commit comments

Comments
 (0)