Skip to content

Commit 5ddbd6a

Browse files
committed
fix(producer): derive duration from sub-composition timing when root has no data-duration
When the root element lacks an explicit data-duration attribute and there is no GSAP timeline, getDeclaredDuration now computes max(data-start + data-duration) across all sub-compositions instead of returning zero.
1 parent f622e5a commit 5ddbd6a

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/producer/src/services/fileServer.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,42 @@ describe("HF_EARLY_STUB + HF_BRIDGE_SCRIPT integration", () => {
567567
sandbox.window.__hfTimelinesBuilding = true;
568568
expect(sandbox.window.__hf?.duration).toBe(0);
569569
});
570+
571+
it("derives duration from sub-composition data-start + data-duration when root has none", () => {
572+
const sandbox: any = {
573+
window: {
574+
setInterval: globalThis.setInterval,
575+
clearInterval: globalThis.clearInterval,
576+
},
577+
document: {
578+
querySelector: () => ({
579+
getAttribute: () => null,
580+
}),
581+
querySelectorAll: () => [
582+
{
583+
getAttribute: (n: string) =>
584+
n === "data-start" ? "0" : n === "data-duration" ? "5" : null,
585+
},
586+
{
587+
getAttribute: (n: string) =>
588+
n === "data-start" ? "5" : n === "data-duration" ? "8" : null,
589+
},
590+
],
591+
},
592+
};
593+
sandbox.window.window = sandbox.window;
594+
sandbox.window.document = sandbox.document;
595+
sandbox.window.__player = {
596+
renderSeek: () => {},
597+
getDuration: () => 0,
598+
};
599+
sandbox.window.__renderReady = true;
600+
601+
new Function("window", "document", `with (window) {\n${HF_BRIDGE_SCRIPT}\n}`)(
602+
sandbox.window,
603+
sandbox.document,
604+
);
605+
606+
expect(sandbox.window.__hf?.duration).toBe(13);
607+
});
570608
});

packages/producer/src/services/fileServer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,15 @@ const HF_BRIDGE_SCRIPT = `(function() {
474474
var root = document.querySelector('[data-composition-id]');
475475
if (!root) return 0;
476476
var d = Number(root.getAttribute('data-duration'));
477-
return Number.isFinite(d) && d > 0 ? d : 0;
477+
if (Number.isFinite(d) && d > 0) return d;
478+
var comps = document.querySelectorAll('[data-composition-src]');
479+
var maxEnd = 0;
480+
for (var i = 0; i < comps.length; i++) {
481+
var start = Number(comps[i].getAttribute('data-start')) || 0;
482+
var dur = Number(comps[i].getAttribute('data-duration')) || 0;
483+
if (dur > 0) maxEnd = Math.max(maxEnd, start + dur);
484+
}
485+
return maxEnd;
478486
}
479487
function seekSameOriginChildFrames(frameWindow, nextTimeMs) {
480488
var frames;

0 commit comments

Comments
 (0)