Skip to content

Commit 1ab2dfb

Browse files
Lucenx9shivamhwp
andauthored
fix(desktop): keep preview picking active across subframe navigation (#9741)
Co-authored-by: Simone <[email protected]> Co-authored-by: shivam <[email protected]>
1 parent 298f8c9 commit 1ab2dfb

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,10 @@ describe("PreviewManager", () => {
35063506
listeners.set(event, listener);
35073507
}),
35083508
once: vi.fn((event: string, listener: (...args: unknown[]) => void) => {
3509-
listeners.set(event, listener);
3509+
listeners.set(event, (...args) => {
3510+
listeners.delete(event);
3511+
listener(...args);
3512+
});
35103513
}),
35113514
off: vi.fn(),
35123515
ipc: { on: vi.fn(), off: vi.fn(), removeListener: vi.fn() },
@@ -3528,11 +3531,23 @@ describe("PreviewManager", () => {
35283531
const pick = yield* manager.pickElement("tab_1").pipe(Effect.forkChild);
35293532
yield* Effect.yieldNow;
35303533

3531-
listeners.get("did-start-navigation")?.({}, "about:blank", false, false);
3534+
listeners.get("did-start-navigation")?.({
3535+
url: "about:blank",
3536+
isSameDocument: false,
3537+
isMainFrame: false,
3538+
frame: null,
3539+
});
35323540
yield* Effect.yieldNow;
35333541
expect(pick.pollUnsafe()).toBeUndefined();
35343542

3535-
listeners.get("did-start-navigation")?.({}, "https://example.com/next", false, true);
3543+
listeners.get("did-start-navigation")?.({
3544+
url: "https://example.com/next",
3545+
isSameDocument: false,
3546+
isMainFrame: true,
3547+
frame: null,
3548+
});
3549+
yield* Effect.yieldNow;
3550+
expect(pick.pollUnsafe()).toBeDefined();
35363551
expect(yield* Fiber.join(pick)).toBeNull();
35373552
}),
35383553
),

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,12 +2566,9 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
25662566
};
25672567
const onDestroyed = () => settle(null);
25682568
const onNavigated = (
2569-
_event: Electron.Event,
2570-
_url: string,
2571-
_isInPlace: boolean,
2572-
isMainFrame: boolean,
2569+
event: Electron.Event<Electron.WebContentsDidStartNavigationEventParams>,
25732570
) => {
2574-
if (isMainFrame) settle(null);
2571+
if (event.isMainFrame) settle(null);
25752572
};
25762573
const registerPickElement = Effect.fn("PreviewManager.registerPickElement")(function* () {
25772574
// Two picks on one tab can overlap. Swap this session in and cancel
@@ -2592,7 +2589,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
25922589
yield* attempt({ operation: "pickElement.register", tabId, webContentsId: wc.id }, () => {
25932590
wc.ipc.on(ELEMENT_PICKED_CHANNEL, onMessage);
25942591
wc.once("destroyed", onDestroyed);
2595-
wc.once("did-start-navigation", onNavigated);
2592+
wc.on("did-start-navigation", onNavigated);
25962593
if (!wc.isFocused()) wc.focus();
25972594
wc.send(START_PICK_CHANNEL, annotationTheme);
25982595
});

0 commit comments

Comments
 (0)