mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
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
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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<HTMLDivElement>(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/")
|
||||
|
||||
Reference in New Issue
Block a user