Repository navigation
fix(server): streamed desktop previews receive viewport dimensions #25455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -617,9 +617,12 @@ const make = Effect.gen(function* () { | |
| }); | ||
| }; | ||
|
|
||
| const broadcastViewport = (tab: ServerTab) => { | ||
| const size = layoutSize(tab); | ||
| if (!size) return; | ||
| const broadcastViewport = async (tab: ServerTab) => { | ||
| let size = layoutSize(tab); | ||
| if (!size) { | ||
| const { width, height } = await ServerBrowserPage.readPageMetrics(tab.cdp); | ||
| size = { width, height }; | ||
| } | ||
| for (const viewer of tab.viewers) viewer.push({ _tag: "viewport", ...size }); | ||
| }; | ||
|
|
||
|
|
@@ -636,7 +639,7 @@ const make = Effect.gen(function* () { | |
| UNATTACHED_FILL_VIEWPORT; | ||
| await tab.page.setViewportSize({ width: size.width, height: size.height }); | ||
| await applyZoom(tab); | ||
| broadcastViewport(tab); | ||
| await broadcastViewport(tab); | ||
| }; | ||
|
|
||
| const applyRendering = async (tab: ServerTab, snapshot: PreviewSessionSnapshot) => { | ||
|
|
@@ -649,7 +652,7 @@ const make = Effect.gen(function* () { | |
| if (zoomFactor !== tab.zoomFactor && !tab.desktop) { | ||
| tab.zoomFactor = zoomFactor; | ||
| await applyZoom(tab); | ||
| broadcastViewport(tab); | ||
| await broadcastViewport(tab); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -777,7 +780,12 @@ const make = Effect.gen(function* () { | |
| captureLock: Promise.resolve(), | ||
| capturing: 0, | ||
| }; | ||
| if (!desktop) { | ||
| if (desktop) { | ||
| cdp.on("Page.frameResized", () => { | ||
| if (tab.viewers.size > 0) void broadcastViewport(tab).catch(constVoid); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔎 Supported by static analysis
Preserve viewport updates when the viewer queue is full. If a desktop viewer's 64-entry output queue is full when
|
||
| }); | ||
| await cdp.send("Page.enable"); | ||
| } else { | ||
| await page.setViewportSize(fixedViewportSize(tab.setting) ?? UNATTACHED_FILL_VIEWPORT); | ||
| } | ||
| await applyRendering(tab, snapshot); | ||
|
|
@@ -2191,7 +2199,7 @@ const make = Effect.gen(function* () { | |
| const current = tab.page.viewportSize(); | ||
| if (current?.width === width && current.height === height) return; | ||
| await tab.page.setViewportSize({ width, height }); | ||
| broadcastViewport(tab); | ||
| await broadcastViewport(tab); | ||
| return; | ||
| } | ||
| case "viewport": { | ||
|
|
@@ -2388,7 +2396,7 @@ const make = Effect.gen(function* () { | |
| ), | ||
| }); | ||
| }); | ||
| broadcastViewport(tab); | ||
| yield* Effect.promise(() => broadcastViewport(tab)); | ||
| yield* Effect.promise(() => startScreencast(1)); | ||
| // An idle page does not repaint for a new screencast, so the viewer | ||
| // starts from a still unless a live frame beat it. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: pingdotgg/t3code
Length of output: 6377
Serialize viewport reads or discard stale results.
Each
Page.frameResizedevent startsbroadcastViewportwithout waiting for earlier calls. WhenlayoutSizeis unavailable,readPageMetricsmakes several CDP round trips, and its zoom check can retry. If an earlier read takes more round trips than a later read, the later read can finish first and push newer dimensions. The earlier read then pushes its older dimensions. The viewer keeps the stale viewport until the next viewport update.Use one of these fixes: