@devries-cameron20 / t3code-1 / commits / 3725817edc
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): input during window teardown no longer throws in the main process (#33620)

Julius Marminge committed Nov 10, 2026 at 13:59 UTC 3725817edc7d0a29d9259502c87b08c9f0e3d6f5
2 files changed +51
apps/desktop/src/window/DesktopWindow.test.ts
+49
@@ -697,6 +697,55 @@ describe("DesktopWindow", () => {
697 }),
698 );
699
700 + it.effect("ignores input that arrives after the window is destroyed", () =>
701 + Effect.gen(function* () {
702 + const fakeWindow = makeFakeBrowserWindow();
703 + const createCount = yield* Ref.make(0);
704 + const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
705 + const layer = layerTest({
706 + window: fakeWindow.window,
707 + createCount,
708 + mainWindow,
709 + });
710 +
711 + yield* Effect.gen(function* () {
712 + const desktopWindow = yield* DesktopWindow.DesktopWindow;
713 + yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
714 +
715 + const beforeInput = fakeWindow.webContentsListeners.get("before-input-event");
716 + const inputEvent = fakeWindow.webContentsListeners.get("input-event");
717 + if (!beforeInput || !inputEvent) {
718 + return yield* Effect.die("input listeners were not registered");
719 + }
720 +
721 + // Electron throws on any member access of a destroyed BrowserWindow.
722 + fakeWindow.isDestroyed.mockReturnValue(true);
723 + Object.defineProperty(fakeWindow.window, "webContents", {
724 + get: () => {
725 + throw new TypeError("Object has been destroyed");
726 + },
727 + });
728 +
729 + // A held Cmd+Q quits from the grace timer, so the trailing Q keyUp lands here.
730 + assert.doesNotThrow(() =>
731 + beforeInput(
732 + { preventDefault: () => {} },
733 + {
734 + type: "keyUp",
735 + isAutoRepeat: false,
736 + key: "q",
737 + meta: true,
738 + control: false,
739 + alt: false,
740 + shift: false,
741 + },
742 + ),
743 + );
744 + assert.doesNotThrow(() => inputEvent({}, { type: "gestureScrollEnd" }));
745 + }).pipe(Effect.provide(layer));
746 + }),
747 + );
748 +
749 // Chromium hands the main window's zoom level down to embedded preview
750 // guests, so every app zoom has to put the preview browser back at its own
751 // zoom or zooming the UI drags the previewed page with it.
apps/desktop/src/window/DesktopWindow.ts
+2
@@ -705,6 +705,7 @@ export const make = Effect.gen(function* () {
705 });
706 window.webContents.on("before-input-event", (event, input) => {
707 quitShortcutHandler(event, input);
708 + if (window.isDestroyed()) return;
709 // Cmd/Ctrl+W reaches the renderer; DevTools uses the native menu shortcut.
710 window.webContents.setIgnoreMenuShortcuts(
711 (environment.platform === "darwin" ? input.meta : input.control) &&
@@ -720,6 +721,7 @@ export const make = Effect.gen(function* () {
721 }
722 });
723 window.webContents.on("input-event", (_event, input) => {
724 + if (window.isDestroyed()) return;
725 if (input.type === "gestureScrollBegin") {
726 window.webContents.send(TRACKPAD_SCROLL_BEGIN_CHANNEL);
727 } else if (input.type === "gestureScrollEnd") {