mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-26 00:57:05 +00:00
fix(studio): a new blank project opens on an empty timeline again (#8546)
This commit is contained in:
@@ -4,6 +4,7 @@ import React, { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { TimelineElement } from "../store/playerStore";
|
||||
import { detachedFakeIframe } from "./timelinePlayerTestHarness";
|
||||
import { useTimelineSyncCallbacks } from "./useTimelineSyncCallbacks";
|
||||
|
||||
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
@@ -39,3 +40,48 @@ describe("processTimelineMessage with an empty manifest", () => {
|
||||
expect(sync).toHaveBeenCalledWith([], undefined);
|
||||
});
|
||||
});
|
||||
|
||||
/** An open preview of `src` showing a root composition with nothing in it. */
|
||||
function emptyRootPreview(src: string, compositionId: string) {
|
||||
const iframe = detachedFakeIframe({});
|
||||
Object.defineProperty(iframe, "src", { value: src, configurable: true });
|
||||
iframe.contentDocument!.body.innerHTML = `<div id="root" data-composition-id="${compositionId}" data-start="0" data-duration="10"></div>`;
|
||||
const sync = vi.fn<(els: TimelineElement[], duration?: number) => void>();
|
||||
let processTimelineMessage: ReturnType<typeof useTimelineSyncCallbacks>["processTimelineMessage"];
|
||||
function Harness() {
|
||||
({ processTimelineMessage } = useTimelineSyncCallbacks({
|
||||
iframeRef: { current: iframe },
|
||||
probeIntervalRef: { current: undefined },
|
||||
pendingSeekRef: { current: null },
|
||||
isRefreshingRef: { current: false },
|
||||
getAdapter: () => null,
|
||||
syncTimelineElements: sync,
|
||||
setDuration: () => {},
|
||||
setCurrentTime: () => {},
|
||||
requestTimelineReady: () => {},
|
||||
setIsPlaying: () => {},
|
||||
attachIframeShortcutListeners: () => {},
|
||||
applyPreviewAudioState: () => {},
|
||||
}));
|
||||
return null;
|
||||
}
|
||||
act(() => createRoot(document.createElement("div")).render(<Harness />));
|
||||
processTimelineMessage!({ clips: [], durationInFrames: 300 });
|
||||
return sync.mock.calls.at(-1)?.[0].map((row) => row.id);
|
||||
}
|
||||
|
||||
describe("an empty clip list's root row", () => {
|
||||
// fails without the fix: a new blank project's timeline showed its own film as one 10 s clip named "main".
|
||||
it("is left out for the project's own film, so a blank project opens on an empty timeline", () => {
|
||||
expect(emptyRootPreview("http://localhost/api/projects/b/preview", "main")).toEqual([]);
|
||||
});
|
||||
|
||||
it("is the one clip of a composition opened on its own", () => {
|
||||
expect(
|
||||
emptyRootPreview(
|
||||
"http://localhost/api/projects/b/preview/comp/compositions/scene5.html",
|
||||
"scene5",
|
||||
),
|
||||
).toEqual(["scene5"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,9 @@ function postLater(init: MessageEventInit): void {
|
||||
setTimeout(() => window.dispatchEvent(new MessageEvent("message", init)));
|
||||
}
|
||||
|
||||
const SCENE_OPENED_ON_ITS_OWN =
|
||||
"http://localhost/api/projects/demo/preview/comp/compositions/scene5.html";
|
||||
|
||||
export interface SealedPreviewFrame {
|
||||
iframe: HTMLIFrameElement;
|
||||
/** The frame's window as Studio sees it: only `postMessage` answers, and it reaches the runtime. */
|
||||
@@ -26,6 +29,7 @@ export function sealedPreviewFrame(
|
||||
});
|
||||
const iframe = detachedFakeIframe(frame);
|
||||
Object.defineProperty(iframe, "contentDocument", { value: null });
|
||||
Object.defineProperty(iframe, "src", { value: SCENE_OPENED_ON_ITS_OWN, configurable: true });
|
||||
let onPageUntilPlayerRemovesIt = true;
|
||||
Object.defineProperty(iframe, "isConnected", {
|
||||
configurable: true,
|
||||
|
||||
@@ -460,6 +460,7 @@ export function buildStandaloneRootTimelineElement(params: {
|
||||
if (!Number.isFinite(params.rootDuration) || params.rootDuration <= 0) return null;
|
||||
|
||||
const compositionSrc = resolveStandaloneRootCompositionSrc(params.iframeSrc);
|
||||
if (compositionSrc === undefined) return null;
|
||||
|
||||
return {
|
||||
id: params.compositionId,
|
||||
|
||||
Reference in New Issue
Block a user