Skip to content

Commit cb7fb7a

Browse files
camchismaria-rcks
andauthored
fix(server): a preview navigation that fails mid-load keeps its failure (#27537)
Co-authored-by: maria-rcks <[email protected]>
1 parent 7c511b3 commit cb7fb7a

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,49 @@ it.live(
10181018
).pipe(Effect.provide(layer)),
10191019
);
10201020

1021+
it.effect("a navigation that fails while a load reads its title keeps its failure", () =>
1022+
Effect.scoped(
1023+
Effect.gen(function* () {
1024+
const { tabId } = yield* ready;
1025+
const manager = yield* Manager.PreviewManager;
1026+
const events = yield* manager.subscribeEvents;
1027+
const page = contexts[0]!.page;
1028+
const heldTitle = Promise.withResolvers<string>();
1029+
page.title.mockImplementationOnce(() => heldTitle.promise);
1030+
yield* Effect.promise(() => page.goto("https://example.com/first"));
1031+
const failing = {
1032+
url: () => "https://example.com/missing",
1033+
method: () => "GET",
1034+
isNavigationRequest: () => true,
1035+
frame: () => page,
1036+
failure: () => ({ errorText: "net::ERR_NAME_NOT_RESOLVED" }),
1037+
};
1038+
page.emit("request", failing);
1039+
page.emit("requestfailed", failing);
1040+
heldTitle.resolve("Held");
1041+
// A load at the same await depth reports after the held one, so its Success marks the end.
1042+
page.emit("load");
1043+
1044+
const statuses: Array<string> = [];
1045+
while (!statuses.at(-1)?.startsWith("Success")) {
1046+
const event = yield* PubSub.take(events);
1047+
if (event.type === "failed" && event.tabId === tabId) {
1048+
statuses.push(`LoadFailed ${event.url}`);
1049+
} else if (event.type === "navigated" && event.tabId === tabId) {
1050+
const status = event.snapshot.navStatus;
1051+
if (status._tag === "Success") statuses.push(`Success ${status.title}`);
1052+
else if (status._tag === "Loading") statuses.push(`Loading ${status.url}`);
1053+
}
1054+
}
1055+
expect(statuses).toEqual([
1056+
"Loading https://example.com/missing",
1057+
"LoadFailed https://example.com/missing",
1058+
"Success test page",
1059+
]);
1060+
}),
1061+
).pipe(Effect.provide(layer)),
1062+
);
1063+
10211064
it.effect.each([
10221065
{
10231066
name: "hover burst before a click",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,10 @@ const make = Effect.gen(function* () {
590590
const url = tab.page.url();
591591
// Chromium's error page loads after `requestfailed` and must not clear LoadFailed.
592592
if (url === "about:blank" || url.startsWith("chrome-error://")) return;
593+
// A navigation that starts and fails during the title read leaves the URL unchanged.
594+
const generation = tab.navigationGeneration;
593595
const title = (await tab.page.title().catch(() => "")).slice(0, 512);
594-
if (tab.loading || tab.page.url() !== url) return;
596+
if (tab.navigationGeneration !== generation || tab.loading || tab.page.url() !== url) return;
595597
report(tab, {
596598
_tag: "Success",
597599
url: ServerBrowserPage.withoutDataPayload(url).slice(0, 2048),

0 commit comments

Comments
 (0)