Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/studio/src/components/nle/NLEPreview.slowBoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLIFrameElement>(),
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();
});
3 changes: 3 additions & 0 deletions packages/studio/src/components/nle/NLEPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface NLEPreviewProps extends Pick<
fillBox?: boolean;
compositionSizeHint?: PreviewCompositionSize;
sandboxOrigin?: "opaque";
noLoadTimeout?: boolean;
}

export function getPreviewPlayerKey({
Expand Down Expand Up @@ -91,6 +92,7 @@ export const NLEPreview = memo(function NLEPreview({
fillBox,
compositionSizeHint,
sandboxOrigin,
noLoadTimeout,
}: NLEPreviewProps) {
const activeKey = getPreviewPlayerKey({ projectId, directUrl });
const viewportRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -518,6 +520,7 @@ export const NLEPreview = memo(function NLEPreview({
portrait={portrait}
suppressLoadingOverlay={suppressLoadingOverlay}
loadingUi={loadingUi}
noLoadTimeout={noLoadTimeout}
sandboxOrigin={sandboxOrigin}
style={
directUrl?.includes("/components/")
Expand Down
Loading