Skip to content

Commit f0e694d

Browse files
committed
fix(server): a preview navigation that fails mid-load keeps its failure
reportLoaded reads the URL, awaits the page title, then reports Success. A main-frame navigation that starts and fails during that await sets loading and then clears it, and Chromium commits its error page only after requestfailed, so the URL still matches. The held report then overwrote the LoadFailed with Success for the old page, and the error page's own report returns early, so the failure stayed hidden. reportLoaded now drops its report when a navigation started during the title read.
1 parent 32ecd71 commit f0e694d

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,45 @@ it.live(
919919
).pipe(Effect.provide(layer)),
920920
);
921921

922+
it.effect("a navigation that fails while a load reads its title keeps its failure", () =>
923+
Effect.scoped(
924+
Effect.gen(function* () {
925+
const { tabId } = yield* ready;
926+
const manager = yield* Manager.PreviewManager;
927+
const events = yield* manager.subscribeEvents;
928+
const page = contexts[0]!.page;
929+
const heldTitle = Promise.withResolvers<string>();
930+
page.title.mockImplementationOnce(() => heldTitle.promise);
931+
yield* Effect.promise(() => page.goto("https://example.com/first"));
932+
const failing = {
933+
url: () => "https://example.com/missing",
934+
method: () => "GET",
935+
isNavigationRequest: () => true,
936+
frame: () => page,
937+
failure: () => ({ errorText: "net::ERR_NAME_NOT_RESOLVED" }),
938+
};
939+
page.emit("request", failing);
940+
page.emit("requestfailed", failing);
941+
heldTitle.resolve("Held");
942+
// A load at the same await depth reports after the held one, so its Success marks the end.
943+
page.emit("load");
944+
945+
let event = yield* PubSub.take(events);
946+
while (
947+
event.type !== "navigated" ||
948+
event.tabId !== tabId ||
949+
event.snapshot.navStatus._tag !== "Success"
950+
) {
951+
event = yield* PubSub.take(events);
952+
}
953+
expect(event.type === "navigated" && event.snapshot.navStatus).toMatchObject({
954+
_tag: "Success",
955+
title: "test page",
956+
});
957+
}),
958+
).pipe(Effect.provide(layer)),
959+
);
960+
922961
it.live("only the controlling viewer's copy and cut keys reach its clipboard", () =>
923962
Effect.scoped(
924963
Effect.gen(function* () {

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,10 @@ const make = Effect.gen(function* () {
578578
const url = tab.page.url();
579579
// Chromium's error page loads after `requestfailed` and must not clear LoadFailed.
580580
if (url === "about:blank" || url.startsWith("chrome-error://")) return;
581+
// A navigation that starts and fails during the title read leaves the URL unchanged.
582+
const generation = tab.navigationGeneration;
581583
const title = (await tab.page.title().catch(() => "")).slice(0, 512);
582-
if (tab.loading || tab.page.url() !== url) return;
584+
if (tab.navigationGeneration !== generation || tab.loading || tab.page.url() !== url) return;
583585
report(tab, { _tag: "Success", url: url.slice(0, 2048), title });
584586
};
585587

0 commit comments

Comments
 (0)