@devries-cameron20 / t3code Mirror · read-only / commits / 4e39664248
Fork 0

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 21, 06:00 UTC

fix(server): preview_resize sizes hidden desktop tabs without a snapshot (#39269)

Julius Marminge committed Nov 19, 2026 at 11:38 UTC 4e3966424802d5c8bc97fc94ceb631adac5d0e05
2 files changed +25 -1
apps/server/src/preview/ServerBrowser.test.ts
+5
@@ -3047,6 +3047,11 @@ it.effect("a desktop tab reports the size the desktop draws after a resize", ()
3047 expect(
3048 yield* resize({ mode: "freeform", width: 900, height: 600 }, 900, 600),
3049 ).toBeUndefined();
3050 + // A hidden guest takes the new size only while the desktop paints it, which a capture asks for.
3051 + expect(cdp.send).toHaveBeenCalledWith(
3052 + "Page.captureScreenshot",
3053 + expect.objectContaining({ clip: expect.anything() }),
3054 + );
3055 desktopSizeAnswer = null;
3056 expect(yield* resize({ mode: "freeform", width: 1280, height: 760 }, 1280, 760)).toEqual({
3057 width: 1280,
apps/server/src/preview/ServerBrowser.ts
+20 -1
@@ -126,6 +126,12 @@ const AGENT_CURSOR_CLICK_LEAD_MS = 40;
126 const DESKTOP_VIEWPORT_READ_TIMEOUT = "1 second";
127 /** A desktop page that keeps its size draws nothing on a resize, so the wait gives up. */
128 const DESKTOP_RESIZE_WAIT_MS = 1000;
129 +/** Answered only once the guest paints a frame; one pixel keeps it cheap. */
130 +const DESKTOP_PAINT_CAPTURE = {
131 + format: "jpeg",
132 + quality: 1,
133 + clip: { x: 0, y: 0, width: 1, height: 1, scale: 1 },
134 +} as const;
135 // A revealed tab's client opens the panel and attaches its stream a few round trips later, remote ones included.
136 const REVEAL_VIEWER_WAIT_MS = 1000;
137 // A desktop panel's shown report waits on the renderer's layout, which a busy machine can push past a second.
@@ -2827,7 +2833,20 @@ const make = Effect.gen(function* () {
2833 // The desktop draws the new size after the session update; its page resize says it has.
2834 // Half the time left keeps room for the read, which runs even if nothing was drawn,
2835 // because a page can keep another size than the one asked for.
2830 - if (changed) await within(drawn, Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2));
2836 + if (changed) {
2837 + // Electron resizes no hidden guest it does not paint; a pending capture makes the desktop paint it.
2838 + let waiting = true;
2839 + void (async () => {
2840 + while (waiting && !tab.closing) {
2841 + await tab.cdp.send("Page.captureScreenshot", DESKTOP_PAINT_CAPTURE);
2842 + }
2843 + })().catch(constVoid);
2844 + try {
2845 + await within(drawn, Math.min(DESKTOP_RESIZE_WAIT_MS, remainingMs() / 2));
2846 + } finally {
2847 + waiting = false;
2848 + }
2849 + }
2850 const changes = tab.desktopViewportChanges;
2851 const measured = await within(measureDesktopViewport(tab), remainingMs());
2852 // Only a read after the draw, with no page resize or load during it, measures this resize.