fix(desktop): keep preview picking active across subframe navigation (#9741)

Co-authored-by: Simone <[email protected]>
Co-authored-by: shivam <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-09-17 16:17:53 +05:30
1 parent 298f8c95cd
commit 1ab2dfb5a7
2 files changed
+21 -9

No files matched your search

+18 -3
View File
@@ -3506,7 +3506,10 @@ describe("PreviewManager", () => {
listeners.set(event, listener);
}),
once: vi.fn((event: string, listener: (...args: unknown[]) => void) => {
listeners.set(event, listener);
listeners.set(event, (...args) => {
listeners.delete(event);
listener(...args);
});
}),
off: vi.fn(),
ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
@@ -3528,11 +3531,23 @@ describe("PreviewManager", () => {
const pick = yield* manager.pickElement("tab_1").pipe(Effect.forkChild);
yield* Effect.yieldNow;
listeners.get("did-start-navigation")?.({}, "about:blank", false, false);
listeners.get("did-start-navigation")?.({
url: "about:blank",
isSameDocument: false,
isMainFrame: false,
frame: null,
});
yield* Effect.yieldNow;
expect(pick.pollUnsafe()).toBeUndefined();
listeners.get("did-start-navigation")?.({}, "https://example.com/next", false, true);
listeners.get("did-start-navigation")?.({
url: "https://example.com/next",
isSameDocument: false,
isMainFrame: true,
frame: null,
});
yield* Effect.yieldNow;
expect(pick.pollUnsafe()).toBeDefined();
expect(yield* Fiber.join(pick)).toBeNull();
}),
),
+3 -6
View File
@@ -2566,12 +2566,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
};
const onDestroyed = () => settle(null);
const onNavigated = (
_event: Electron.Event,
_url: string,
_isInPlace: boolean,
isMainFrame: boolean,
event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
) => {
if (isMainFrame) settle(null);
if (event.isMainFrame) settle(null);
};
const registerPickElement = Effect.fn("PreviewManager.registerPickElement")(function* () {
// Two picks on one tab can overlap. Swap this session in and cancel
@@ -2592,7 +2589,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
wc.once("destroyed", onDestroyed);
wc.once("did-start-navigation", onNavigated);
wc.on("did-start-navigation", onNavigated);
if (!wc.isFocused()) wc.focus();
wc.send(START_PICK_CHANNEL, annotationTheme);
});