Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/server/src/preview/ServerBrowser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,47 @@ it.live("reports a pending dialog without evaluating the page and resolves it ex
).pipe(Effect.provide(layer)),
);

it.live("a dialog the browser already closed stops blocking the tab", () =>
Effect.scoped(
Effect.gen(function* () {
const { broker, tabId } = yield* ready;
const page = contexts[0]!.page;
yield* broker.invoke({
scope,
tabId,
operation: "navigate",
input: { url: "http://localhost:5173" },
});
page.emit("dialog", {
type: () => "beforeunload",
message: () => "",
defaultValue: () => "",
accept: vi.fn(async () => {
throw new Error("Protocol error (Page.handleJavaScriptDialog): No dialog is showing");
}),
dismiss: vi.fn(async () => {}),
});
yield* broker
.invoke<void>({ scope, tabId, operation: "dialog", input: { accept: true } })
.pipe(Effect.flip);
const status = yield* broker.invoke<PreviewAutomationStatus>({
scope,
tabId,
operation: "status",
input: {},
});
expect(status.dialog).toBeNull();
yield* broker.invoke({
scope,
tabId,
operation: "navigate",
input: { url: "http://localhost:5173/other" },
});
expect(page.goto).toHaveBeenCalledTimes(2);
}),
).pipe(Effect.provide(layer)),
);

it.live("a tab opened to a file the browser cannot show reports the file to download", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
14 changes: 9 additions & 5 deletions apps/server/src/preview/ServerBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,15 @@ const make = Effect.gen(function* () {
const resolveDialog = async (tab: ServerTab, input: PreviewAutomationDialogInput) => {
const dialog = tab.dialog;
if (!dialog) throw new Error("No dialog is pending.");
if (input.accept) await dialog.accept(input.promptText);
else await dialog.dismiss();
if (tab.dialog === dialog) tab.dialog = null;
ServerBrowserPage.invalidateRefs(tab.page);
broadcastControl(tab);
try {
if (input.accept) await dialog.accept(input.promptText);
else await dialog.dismiss();
} finally {
// A failed answer means the browser already closed the dialog. Keeping it would block the tab.
if (tab.dialog === dialog) tab.dialog = null;
ServerBrowserPage.invalidateRefs(tab.page);
broadcastControl(tab);
}
};

const report = (tab: ServerTab, navStatus: PreviewNavStatus) => {
Expand Down
Loading