Files
hyperframes/packages/studio/src/utils/previewCompositionSize.ts
T
Miguel Ángel 85a1a8f789 fix(studio): swap the preview via a shadow iframe instead of blanking on reload (#4207)
* fix(studio): reloading the preview swaps in a ready copy instead of blanking

* fix(player): report painted once assets are ready and the loader has faded out

assetsready fires when the loader fade starts, so a consumer promoting on it can
expose a raised or fading panel. painted fires once per document load after the
fade completes, with a getter for late listeners; it resets on each load.

* fix(studio): promote the shadow preview only when painted, under one wait budget

Studio waited for ready plus two frames, which can land while the player's loader
panel is still up or fading. It now also waits for the player's painted event.
The shadow no longer arms the 5s adapter give-up, so a slow but live load fails
only at the single 15s budget. Set-destination availability follows the live
iframe across a swap.
2026-09-20 13:04:23 -04:00

27 lines
884 B
TypeScript

export interface PreviewCompositionSize {
width: number;
height: number;
}
/** The root composition's authored size, read from the preview document itself. */
// fallow-ignore-next-line complexity
export function readPreviewCompositionSize(
iframe: HTMLIFrameElement | null,
): PreviewCompositionSize | null {
try {
const doc = iframe?.contentDocument;
const root =
doc?.querySelector("[data-composition-id][data-width][data-height]") ??
doc?.querySelector("[data-width][data-height]");
if (!root) return null;
const width = Number.parseInt(root.getAttribute("data-width") ?? "", 10);
const height = Number.parseInt(root.getAttribute("data-height") ?? "", 10);
if (!Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0) {
return null;
}
return { width, height };
} catch {
return null;
}
}