Skip to content

Commit 9ef9043

Browse files
fix(web): browser find no longer reopens empty after switching tabs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d497148 commit 9ef9043

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ vi.mock(import("./previewBridge"), async (original) => ({
7272
open: mocks.openPictureInPicture,
7373
close: mocks.closePictureInPicture,
7474
},
75+
findInPage: vi.fn(async () => undefined),
76+
stopFindInPage: vi.fn(async () => undefined),
77+
onFindResult: vi.fn(() => () => undefined),
7578
} as never,
7679
}));
7780
vi.mock(import("~/browserHistoryStore"), async (original) => ({
@@ -286,4 +289,21 @@ describe("PreviewView", () => {
286289
act(() => dispatchPreviewAction("focus-url"));
287290
await expect.element(address).toHaveFocus();
288291
});
292+
293+
it("does not reopen find when the user returns to a tab they left with find open", async () => {
294+
setup();
295+
const tabView = (tabId: string) => (
296+
<PreviewView threadRef={TEST_THREAD_REF} tabId={tabId} visible />
297+
);
298+
await using screen = await render(tabView("tab-1"));
299+
const findBar = page.getByRole("search", { name: "Find in page" });
300+
301+
act(() => dispatchPreviewAction("find"));
302+
await expect.element(findBar).toBeInTheDocument();
303+
304+
await screen.rerender(tabView("tab-2"));
305+
await expect.element(findBar).not.toBeInTheDocument();
306+
await screen.rerender(tabView("tab-1"));
307+
await expect.element(findBar).not.toBeInTheDocument();
308+
});
289309
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export function PreviewView({
190190
const runtimeTabId = tabId
191191
? previewRuntimeTabId(threadRef, previewState.serverEpoch, tabId)
192192
: null;
193+
if (find !== null && find.tabId !== runtimeTabId) setFind(null);
193194
const recordingRuntimeTabId =
194195
tabId && runtimeTabId
195196
? activeRecordingTabIds.has(runtimeTabId)

0 commit comments

Comments
 (0)