Skip to content

Commit 76d3f97

Browse files
PR Batch Testerclaude
andcommitted
fix(server): desktop size reads wait out an open dialog
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9df34f4 commit 76d3f97

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,22 @@ it.effect(
12141214
};
12151215
};
12161216
deferReads();
1217-
const { viewer, cdp } = yield* openDesktopViewer;
1217+
const { viewer, cdp, context } = yield* openDesktopViewer;
12181218
const answer = (width: number, height: number) => ({
12191219
result: { value: { width, height } },
12201220
});
12211221
const resized = () => cdp.emitAsync("Page.frameResized");
12221222
// An alert open on attach blocks the first read, which gives up with no size to send.
12231223
const blocked = yield* Queue.take(reads);
12241224
yield* TestClock.adjust("1 second");
1225+
// While it stays open nothing reads again; the host closing it clears it.
1226+
context.page.emit("dialog", {
1227+
type: () => "alert",
1228+
message: () => "",
1229+
defaultValue: () => "",
1230+
});
1231+
yield* Effect.promise(resized);
1232+
expect(yield* Queue.size(reads)).toBe(0);
12251233
// Closing it resizes nothing, so the close itself remeasures.
12261234
desktopSizeAnswer = null;
12271235
yield* Effect.promise(() => cdp.emitAsync("Page.javascriptDialogClosed"));

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ const make = Effect.gen(function* () {
650650
}));
651651

652652
const layoutSize = async (tab: ServerTab) => {
653-
if (tab.desktop) return measureDesktopViewport(tab);
653+
// A dialog blocks page script; its close measures again.
654+
if (tab.desktop) return tab.dialog ? tab.desktopViewport : measureDesktopViewport(tab);
654655
const size = tab.page.viewportSize();
655656
if (!size) return size;
656657
return {
@@ -857,8 +858,11 @@ const make = Effect.gen(function* () {
857858
if (tab.viewers.size > 0) return broadcastViewport(tab).catch(constVoid);
858859
};
859860
cdp.on("Page.frameResized", remeasure);
860-
// A dialog blocks size reads, and closing one resizes nothing.
861-
cdp.on("Page.javascriptDialogClosed", remeasure);
861+
// Closing a dialog resizes nothing, and the host can close it without us.
862+
cdp.on("Page.javascriptDialogClosed", () => {
863+
tab.dialog = null;
864+
return remeasure();
865+
});
862866
await cdp.send("Page.enable");
863867
}
864868
const isMainNavigation = (request: { isNavigationRequest(): boolean; frame(): unknown }) =>

0 commit comments

Comments
 (0)