Skip to content

Commit 4d9d5ba

Browse files
committed
fix(core): resolve long nested media in local time
1 parent af1cb1c commit 4d9d5ba

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,41 @@ describe("initSandboxRuntimeModular", () => {
11871187
expect(video.style.visibility).toBe("visible");
11881188
});
11891189

1190+
it("keeps a long video starting at zero local to its delayed composition host", () => {
1191+
const root = document.createElement("div");
1192+
root.setAttribute("data-composition-id", "main");
1193+
root.setAttribute("data-root", "true");
1194+
root.setAttribute("data-start", "0");
1195+
root.setAttribute("data-duration", "120");
1196+
document.body.appendChild(root);
1197+
1198+
const host = document.createElement("div");
1199+
host.setAttribute("data-composition-id", "nested-video");
1200+
host.setAttribute("data-composition-file", "compositions/nested.html");
1201+
host.setAttribute("data-start", "39.233");
1202+
host.setAttribute("data-duration", "80");
1203+
root.appendChild(host);
1204+
1205+
const video = document.createElement("video");
1206+
video.setAttribute("data-start", "0");
1207+
video.setAttribute("data-duration", "80");
1208+
video.load = () => {};
1209+
host.appendChild(video);
1210+
1211+
window.__timelines = {
1212+
main: createMockTimeline(120),
1213+
"nested-video": createMockTimeline(80),
1214+
};
1215+
1216+
initSandboxRuntimeModular();
1217+
1218+
expect(window.__hfResolveMediaStartSeconds?.(video)).toBeCloseTo(39.233);
1219+
window.__player?.renderSeek(80.4);
1220+
expect(video.style.visibility).toBe("visible");
1221+
window.__player?.renderSeek(111);
1222+
expect(video.style.visibility).toBe("visible");
1223+
});
1224+
11901225
it("uses the canonical resolver for reference starts, auto-start media, and inline hosts", () => {
11911226
const root = document.createElement("div");
11921227
root.setAttribute("data-composition-id", "main");

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -663,22 +663,15 @@ export function initSandboxRuntimeModular(): void {
663663
// Both timing conventions exist in shipped projects:
664664
// - composition-local media, e.g. host@20 + video@0 => root@20
665665
// - legacy root-global PIP media, e.g. [email protected] + [email protected] => [email protected]
666-
// Preserve the global value when its authored window already intersects
667-
// the host's absolute window. Otherwise it is unambiguously local and
668-
// must inherit the recursively-resolved host start.
669-
const authoredDuration = parseStrictFiniteTimingNumber(element.getAttribute("data-duration"));
666+
// Preserve the global value when its authored start already falls inside
667+
// the host's absolute window. A long local clip can overlap that window
668+
// even when its start is local ([email protected] + video@0/duration=80), so the
669+
// duration cannot disambiguate the timing convention.
670670
const hostDuration = context.inheritedDuration;
671671
const hostEnd = hostDuration != null && hostDuration > 0 ? inheritedStart + hostDuration : null;
672-
const authoredEnd =
673-
authoredDuration != null && authoredDuration > 0
674-
? authoredStart + authoredDuration
675-
: authoredStart;
676-
const overlapsHostWindow =
677-
hostEnd == null
678-
? authoredStart >= inheritedStart
679-
: authoredStart < hostEnd &&
680-
(authoredEnd > inheritedStart || authoredStart === inheritedStart);
681-
return overlapsHostWindow ? authoredStart : inheritedStart + authoredStart;
672+
const startsInsideHostWindow =
673+
authoredStart >= inheritedStart && (hostEnd == null || authoredStart < hostEnd);
674+
return startsInsideHostWindow ? authoredStart : inheritedStart + authoredStart;
682675
};
683676

684677
window.__hfResolveMediaStartSeconds = resolveAbsoluteMediaStartSeconds;

0 commit comments

Comments
 (0)