Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(core): un-hide a later root-level clip instead of leaving it display:none forever (#3893)
miga-heygen1acc65dbf813
diff --git a/packages/core/src/runtime/init.test.ts b/packages/core/src/runtime/init.test.tsindex caee25f81e..cae10882d3 100644--- a/packages/core/src/runtime/init.test.ts+++ b/packages/core/src/runtime/init.test.ts@@ -2344,6 +2344,53 @@ describe("initSandboxRuntimeModular", () => {expect(video.style.visibility).toBe("hidden");});+ it("un-hides a later root-level video once active, even though it starts inactive and unstyled", () => {+ // Root-level `[data-start]` children with no authored `position` start out+ // `position: static` until `applyClipLayout` force-absolutizes them, so a+ // visibility pass over the still-inactive second clip can observe `static`+ // and cache it as in-flow before that forcing runs. The un-hide path used to+ // re-derive that in-flow status rather than track whether it had actually+ // applied `display:none`, so the corrected, no-longer-in-flow reading made+ // it skip the removal and the clip stayed `display:none` for the rest of the+ // render even once active.+ const root = document.createElement("div");+ root.setAttribute("data-composition-id", "main");+ root.setAttribute("data-root", "true");+ root.setAttribute("data-start", "0");+ root.setAttribute("data-duration", "20");+ root.setAttribute("data-width", "1920");+ root.setAttribute("data-height", "1080");+ document.body.appendChild(root);++ const clipA = document.createElement("video");+ clipA.id = "clip-a";+ clipA.setAttribute("data-start", "0");+ clipA.setAttribute("data-duration", "10");+ root.appendChild(clipA);++ const clipB = document.createElement("video");+ clipB.id = "clip-b";+ clipB.setAttribute("data-start", "10");+ clipB.setAttribute("data-duration", "10");+ root.appendChild(clipB);++ window.__timelines = { main: createMockTimeline(20) };++ initSandboxRuntimeModular();++ const player = window.__player;+ expect(player).toBeDefined();++ // Evaluate the still-inactive second clip at least once before it becomes+ // active — the shape that used to poison the cache.+ player?.seek(0);+ expect(clipB.style.visibility).toBe("hidden");++ player?.seek(15);+ expect(clipB.style.visibility).toBe("visible");+ expect(clipB.style.display).not.toBe("none");+ });+it("allocates color grading only for the active timed media", () => {const getContextSpy = vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);const root = document.createElement("div");diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.tsindex b53883af10..eae0f61dc4 100644--- a/packages/core/src/runtime/init.ts+++ b/packages/core/src/runtime/init.ts@@ -2274,6 +2274,15 @@ export function initSandboxRuntimeModular(): void {timedClipInFlow = new WeakMap<Element, boolean>();timedClipIsLeaf = new WeakMap<Element, boolean>();};++ // Which elements carry a `display:none` the visibility pass itself applied, so+ // the un-hide branch can undo exactly that instead of re-deriving+ // `isTimedClipInFlow`. That derived answer can flip between the hide and the+ // show pass for the SAME element — `applyClipLayout` force-absolutizes a+ // root-level clip after an earlier pass already cached it as in-flow and hid+ // it — and the corrected, no-longer-in-flow reading then skips the removal,+ // stranding the clip hidden for the rest of the render.+ const timedClipDisplayNoneApplied = new WeakSet<HTMLElement>();const dataHiddenDisplayRestores = new WeakMap<HTMLElement, string>();const dataHiddenDisplayNodes = new WeakSet<HTMLElement>();// A data-hidden toggle on (or affecting) an audio element must re-schedule@@ -2368,9 +2377,13 @@ export function initSandboxRuntimeModular(): void {colorGradingRuntime?.setSourceVisibility(rawNode, isVisibleNow);}if (isVisibleNow) {- if (isTimedClipInFlow(rawNode)) rawNode.style.removeProperty("display");+ if (timedClipDisplayNoneApplied.has(rawNode)) {+ rawNode.style.removeProperty("display");+ timedClipDisplayNoneApplied.delete(rawNode);+ }} else if (isTimedClipInFlow(rawNode) && isTimedClipLeaf(rawNode)) {rawNode.style.display = "none";+ timedClipDisplayNoneApplied.add(rawNode);}}// Only when a `data-hidden` mutation actually moved something: the skipsdiff --git a/packages/producer/src/services/coreRuntimeBrowser.test.ts b/packages/producer/src/services/coreRuntimeBrowser.test.tsindex 3147689f33..9a6cc4cba3 100644--- a/packages/producer/src/services/coreRuntimeBrowser.test.ts+++ b/packages/producer/src/services/coreRuntimeBrowser.test.ts@@ -148,6 +148,65 @@ describe("core runtime browser contract", () => {30_000,);+ it("un-hides a later root-level video once active, even though it starts inactive and unstyled", async () => {+ // Root-level `[data-start]` children with no authored `position` start out+ // `position: static` until the runtime force-absolutizes them, so a+ // visibility pass over the still-inactive second clip can observe `static`+ // and cache it as in-flow before that forcing runs. That cached reading used+ // to poison the later un-hide check and leave the clip stuck `display:none`+ // for the rest of the render once it became active.+ const videoPage = await browser.newPage();+ try {+ await videoPage.setContent(`<!doctype html>+ <div+ data-composition-id="root"+ data-start="0"+ data-duration="20"+ data-width="320"+ data-height="240"+ >+ <video id="clip-a" data-start="0" data-duration="10" width="320" height="240" muted></video>+ <video id="clip-b" data-start="10" data-duration="10" width="320" height="240" muted></video>+ </div>`);+ await videoPage.addScriptTag({ content: readFileSync(RUNTIME_PATH, "utf8") });+ await videoPage.waitForFunction(+ () =>+ (window as unknown as { __playerReady?: boolean }).__playerReady === true &&+ (window as unknown as { __renderReady?: boolean }).__renderReady === true,+ );++ const seekAndReadClipB = (seekTo: number) =>+ videoPage.evaluate((timeSeconds) => {+ const player = (+ window as unknown as { __player?: { renderSeek: (timeSeconds: number) => void } }+ ).__player;+ if (!player) throw new Error("runtime player was not installed");+ player.renderSeek(timeSeconds);++ const clip = document.getElementById("clip-b");+ if (!clip) throw new Error("clip-b was not found");+ const computed = window.getComputedStyle(clip);+ return {+ display: computed.display,+ visibility: computed.visibility,+ offsetWidth: clip.offsetWidth,+ };+ }, seekTo);++ // Evaluate the still-inactive second clip at least once before it+ // becomes active — the shape that used to poison the cache.+ const beforeActive = await seekAndReadClipB(0);+ expect(beforeActive.visibility).toBe("hidden");++ const afterActive = await seekAndReadClipB(15);+ expect(afterActive.visibility).toBe("visible");+ expect(afterActive.display).not.toBe("none");+ expect(afterActive.offsetWidth).toBeGreaterThan(0);+ } finally {+ await videoPage.close();+ }+ }, 30_000);+it("removes the control bridge during teardown", async () => {const result = await page.evaluate(async () => {const runtimeWindow = window as unknown as {