The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 02:00 UTC
fix(desktop): page redirects during loading no longer show a navigation error (#28814)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
shivam committed
Nov 9, 2026 at 19:58 UTC
0e65e6332408db1841f6664e6b76df4959e7b26a
2 files changed
+65
-2
apps/desktop/src/preview/Manager.test.ts
+47
@@ -824,6 +824,53 @@ describe("PreviewManager", () => {
824
),
825
);
826
827
+ effectIt.effect("treats a load superseded by a page redirect as a successful navigation", () =>
828
+ withManager((manager) =>
829
+ Effect.gen(function* () {
830
+ // Same shape Electron's loadURL rejects with in lib/browser/api/web-contents.ts.
831
+ const loadError = (errno: number, code: string, url: string) =>
832
+ Object.assign(new Error(`${code} (${errno}) loading '${url}'`), { errno, code, url });
833
+ const preview = makeFaviconWebContents();
834
+ fromId.mockReturnValue(preview.webContents);
835
+ yield* manager.createTab("tab_redirect");
836
+ yield* manager.registerWebview("tab_redirect", 42);
837
+
838
+ preview.loadURL.mockRejectedValueOnce(
839
+ loadError(-3, "ERR_ABORTED", "https://example.com/target"),
840
+ );
841
+ yield* manager.navigate("tab_redirect", "https://example.com/");
842
+
843
+ preview.loadURL.mockRejectedValueOnce(
844
+ loadError(-3, "ERR_ABORTED", "https://example.com/reload"),
845
+ );
846
+ yield* manager.navigate("tab_redirect", "https://example.com/reload");
847
+
848
+ preview.loadURL.mockImplementationOnce(async () => {
849
+ preview.listeners.get("will-prevent-unload")?.();
850
+ throw loadError(-3, "ERR_ABORTED", "https://example.com/blocked");
851
+ });
852
+ const blocked = yield* Effect.exit(
853
+ manager.navigate("tab_redirect", "https://example.com/blocked"),
854
+ );
855
+ expect(Exit.isFailure(blocked)).toBe(true);
856
+
857
+ preview.loadURL.mockRejectedValueOnce(
858
+ loadError(-105, "ERR_NAME_NOT_RESOLVED", "https://missing.invalid/"),
859
+ );
860
+ const failed = yield* Effect.exit(
861
+ manager.navigate("tab_redirect", "https://missing.invalid/"),
862
+ );
863
+ expect(Exit.isFailure(failed)).toBe(true);
864
+ if (Exit.isSuccess(failed)) return;
865
+ expect(Option.getOrThrow(Cause.findErrorOption(failed.cause))).toMatchObject({
866
+ _tag: "PreviewOperationError",
867
+ operation: "navigate.loadURL",
868
+ cause: { errno: -105 },
869
+ });
870
+ }),
871
+ ),
872
+ );
873
+
874
effectIt.effect("detaches through the pinned debugger after the webview is destroyed", () =>
875
withManager((manager) =>
876
Effect.gen(function* () {
apps/desktop/src/preview/Manager.ts
+18
-2
@@ -48,6 +48,7 @@ import * as Fiber from "effect/Fiber";
48
import * as Layer from "effect/Layer";
49
import * as Option from "effect/Option";
50
import * as Path from "effect/Path";
51
+import * as Predicate from "effect/Predicate";
52
import * as Queue from "effect/Queue";
53
import * as Ref from "effect/Ref";
54
import * as Schema from "effect/Schema";
@@ -2009,8 +2010,23 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
2010
);
2011
return;
2012
}
2012
- yield* attemptPromise({ operation: "navigate.loadURL", tabId, webContentsId: wc.id }, () =>
2013
- wc.loadURL(url),
2013
+ let unloadPrevented = false;
2014
+ const onPreventUnload = () => {
2015
+ unloadPrevented = true;
2016
+ };
2017
+ yield* attemptPromise({ operation: "navigate.loadURL", tabId, webContentsId: wc.id }, () => {
2018
+ wc.on("will-prevent-unload", onPreventUnload);
2019
+ return wc.loadURL(url);
2020
+ }).pipe(
2021
+ // Blocked unloads and superseding navigations both reject with ERR_ABORTED.
2022
+ Effect.catchIf(
2023
+ (error) =>
2024
+ !unloadPrevented &&
2025
+ Predicate.hasProperty(error.cause, "errno") &&
2026
+ error.cause.errno === -3,
2027
+ () => Effect.void,
2028
+ ),
2029
+ Effect.ensuring(Effect.sync(() => wc.off("will-prevent-unload", onPreventUnload))),
2030
);
2031
});
2032