Skip to content
TypeScript

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

Simone1ab2dfb5a7bd
diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts
index 66c91981b66..7b76a1b8003 100644
--- a/apps/desktop/src/preview/Manager.test.ts
+++ b/apps/desktop/src/preview/Manager.test.ts
@@ -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();
}),
),
diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts
index 7cf73af91e9..a2e34fe5473 100644
--- a/apps/desktop/src/preview/Manager.ts
+++ b/apps/desktop/src/preview/Manager.ts
@@ -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);
});