Skip to content

Commit 3aa5cf3

Browse files
authored
fix(core): update nested timed element visibility on seek (#823)
1 parent 0df6985 commit 3aa5cf3

2 files changed

Lines changed: 52 additions & 15 deletions

File tree

packages/core/src/runtime/init.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,58 @@ describe("initSandboxRuntimeModular", () => {
263263
expect(video.currentTime).toBe(9);
264264
});
265265

266+
it("updates visibility for timed elements inside nested compositions", () => {
267+
const root = document.createElement("div");
268+
root.setAttribute("data-composition-id", "main");
269+
root.setAttribute("data-root", "true");
270+
root.setAttribute("data-start", "0");
271+
root.setAttribute("data-width", "1920");
272+
root.setAttribute("data-height", "1080");
273+
document.body.appendChild(root);
274+
275+
const child = document.createElement("div");
276+
child.setAttribute("data-composition-id", "nested");
277+
child.setAttribute("data-start", "10");
278+
child.setAttribute("data-duration", "10");
279+
root.appendChild(child);
280+
281+
const sceneA = document.createElement("section");
282+
sceneA.id = "scene-a";
283+
sceneA.setAttribute("data-start", "0");
284+
sceneA.setAttribute("data-duration", "4");
285+
child.appendChild(sceneA);
286+
287+
const sceneB = document.createElement("section");
288+
sceneB.id = "scene-b";
289+
sceneB.setAttribute("data-start", "4");
290+
sceneB.setAttribute("data-duration", "4");
291+
child.appendChild(sceneB);
292+
293+
(window as Window & { __timelines?: Record<string, RuntimeTimelineLike> }).__timelines = {
294+
main: createMockTimeline(20),
295+
nested: createMockTimeline(8),
296+
};
297+
298+
initSandboxRuntimeModular();
299+
300+
const player = (
301+
window as Window & {
302+
__player?: { seek: (timeSeconds: number) => void };
303+
}
304+
).__player;
305+
expect(player).toBeDefined();
306+
307+
player?.seek(11);
308+
309+
expect(sceneA.style.visibility).toBe("visible");
310+
expect(sceneB.style.visibility).toBe("hidden");
311+
312+
player?.seek(15);
313+
314+
expect(sceneA.style.visibility).toBe("hidden");
315+
expect(sceneB.style.visibility).toBe("visible");
316+
});
317+
266318
it("clamps nested media to the authored host window on seek", () => {
267319
const root = document.createElement("div");
268320
root.setAttribute("data-composition-id", "main");

packages/core/src/runtime/init.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,27 +1316,12 @@ export function initSandboxRuntimeModular(): void {
13161316
postRuntimeMessage({ source: "hf-preview", type: "media-autoplay-blocked" });
13171317
},
13181318
});
1319-
const rootCompId =
1320-
document.querySelector("[data-composition-id]")?.getAttribute("data-composition-id") ?? null;
13211319
const visibilityNodes = Array.from(document.querySelectorAll("[data-start]"));
13221320
for (const rawNode of visibilityNodes) {
13231321
if (!(rawNode instanceof HTMLElement)) continue;
13241322
const tag = rawNode.tagName.toLowerCase();
13251323
if (tag === "script" || tag === "style" || tag === "link" || tag === "meta") continue;
13261324

1327-
// Skip elements INSIDE sub-compositions — their visibility is managed by GSAP,
1328-
// not the global time-based adapter. Only manage visibility for:
1329-
// 1. Composition host elements (have data-composition-id themselves)
1330-
// 2. Direct children of root composition (audio, etc.)
1331-
// Skip: elements whose nearest composition ancestor is NOT the root
1332-
const ownCompId = rawNode.getAttribute("data-composition-id");
1333-
if (!ownCompId) {
1334-
// Not a composition host — check if it's inside a sub-composition
1335-
const parentComp = rawNode.closest("[data-composition-id]");
1336-
const parentCompId = parentComp?.getAttribute("data-composition-id") ?? null;
1337-
if (parentCompId && parentCompId !== rootCompId) continue;
1338-
}
1339-
13401325
const start = resolveStartForElement(rawNode, 0);
13411326
let duration = resolveDurationForElement(rawNode);
13421327
const compId = rawNode.getAttribute("data-composition-id");

0 commit comments

Comments
 (0)