From 44d805c444304fb9b4e8d4f4ff8b12fcbdb32f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 20 Nov 2026 18:46:00 +0000 Subject: [PATCH] fix(studio): a host can own the live preview's load deadline, so a slow sealed film isn't an error (#8206) * test(studio): a sealed preview whose film boots after 8 s comes ready without an error * test(studio): wait for the sealed player to mount before reading it * fix(studio): a host can own the live preview's load deadline, so a slow sealed film isn't an error --- .../nle/NLEPreview.slowBoot.test.ts | 54 +++++++++++++++++++ .../studio/src/components/nle/NLEPreview.tsx | 3 ++ 2 files changed, 57 insertions(+) diff --git a/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts b/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts index dd2fe32262..c5b0d3c48e 100644 --- a/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts +++ b/packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts @@ -60,3 +60,57 @@ it("keeps a shadow reload whose runtime boots after 8 s, and its player comes re expect(host.querySelector("hyperframes-player")?.hasAttribute("no-load-timeout")).toBe(false); act(() => root.unmount()); }); + +// fails without the fix: the live player kept its own 8 s deadline and a sealed film that came up later had errored. +it("hands the live preview's load deadline to a host that owns it, so a sealed film booting after 8 s comes ready", async () => { + await import("@hyperframes/player"); + const frameToken = vi + .spyOn(globalThis, "fetch") + .mockResolvedValue({ ok: true, json: async () => ({ token: "T".repeat(43) }) } as Response); + vi.useFakeTimers(); + const host = document.createElement("div"); + document.body.append(host); + const root = createRoot(host); + await act(async () => { + root.render( + React.createElement(NLEPreview, { + projectId: "p", + iframeRef: createRef(), + onIframeLoad: () => {}, + previewSlots: [{ gen: 0, role: "live" }], + onShadowIframeLoad: () => {}, + onShadowReadyChange: () => {}, + onShadowError: () => {}, + setShadowIframeNode: () => {}, + resetPreviewSlots: () => {}, + sandboxOrigin: "opaque", + noLoadTimeout: true, + }), + ); + for (let i = 0; i < 10; i += 1) await Promise.resolve(); + }); + + const live = host.querySelector< + HTMLElement & { iframeElement: HTMLIFrameElement; ready: boolean } + >("hyperframes-player")!; + const errors: unknown[] = []; + live.addEventListener("error", (event) => errors.push((event as CustomEvent).detail)); + const iframe = live.iframeElement; + act(() => { + iframe.dispatchEvent(new Event("load")); + }); + act(() => { + vi.advanceTimersByTime(10_000); + }); + expect(errors).toEqual([]); + + Object.assign(iframe.contentWindow!, { __player: { getDuration: () => 9 } }); + act(() => { + vi.advanceTimersByTime(1_000); + }); + expect(errors).toEqual([]); + expect(live.ready).toBe(true); + expect(live.hasAttribute("sandbox-origin")).toBe(true); + act(() => root.unmount()); + frameToken.mockRestore(); +}); diff --git a/packages/studio/src/components/nle/NLEPreview.tsx b/packages/studio/src/components/nle/NLEPreview.tsx index 6a33f90b70..7d5a210bf1 100644 --- a/packages/studio/src/components/nle/NLEPreview.tsx +++ b/packages/studio/src/components/nle/NLEPreview.tsx @@ -56,6 +56,7 @@ interface NLEPreviewProps extends Pick< fillBox?: boolean; compositionSizeHint?: PreviewCompositionSize; sandboxOrigin?: "opaque"; + noLoadTimeout?: boolean; } export function getPreviewPlayerKey({ @@ -91,6 +92,7 @@ export const NLEPreview = memo(function NLEPreview({ fillBox, compositionSizeHint, sandboxOrigin, + noLoadTimeout, }: NLEPreviewProps) { const activeKey = getPreviewPlayerKey({ projectId, directUrl }); const viewportRef = useRef(null); @@ -518,6 +520,7 @@ export const NLEPreview = memo(function NLEPreview({ portrait={portrait} suppressLoadingOverlay={suppressLoadingOverlay} loadingUi={loadingUi} + noLoadTimeout={noLoadTimeout} sandboxOrigin={sandboxOrigin} style={ directUrl?.includes("/components/")