fix(core): a timeline whose labels throw no longer empties the clip list (#8512)

* test: one timeline's throwing labels don't empty the clip list

* fix(core): a timeline whose labels throw leaves only its own clips unlabeled
This commit is contained in:
Miguel Ángel
2026-11-22 15:24:10 +00:00
committed by GitHub
parent f38a4e3675
commit 5d4420fee1
2 changed files with 37 additions and 2 deletions
@@ -139,6 +139,34 @@ describe("collectRuntimeTimelinePayload", () => {
]);
});
it("still lists every clip, with the labels it can read, when one timeline's labels throw", () => {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
root.setAttribute("data-duration", "10");
root.innerHTML = `
<div id="a" data-start="0" data-duration="3" data-track-index="0"></div>
<div id="b" data-start="2" data-duration="3" data-track-index="0"></div>`;
document.body.appendChild(root);
(window as TimelineTestWindow).__timelines = {
broken: {
duration: () => 10,
getLabels: () => {
throw new Error("a page's own timeline");
},
} as never,
main: { duration: () => 10, labels: { "hf:transition:a:b:fade": 2 } } as never,
};
const labels = collectRuntimeTimelinePayload(defaultParams).clips.map((clip) => [
clip.id,
clip.transitionLabel,
]);
expect(labels).toEqual([
["a", "hf:transition:a:b:fade"],
["b", "hf:transition:a:b:fade"],
]);
});
it("collects clips from elements with data-start and data-duration", () => {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
@@ -26,6 +26,14 @@ function findTimedElement(doc: Document, markerId: string): Element | null {
);
}
function labelsOf(timeline: TimelineWithLabels | undefined): Record<string, number> {
try {
return timeline?.getLabels?.() ?? timeline?.labels ?? {};
} catch {
return {};
}
}
export function transitionLabelsForDocument(
doc: Document,
timelines: Readonly<Record<string, object | undefined>> | undefined,
@@ -34,8 +42,7 @@ export function transitionLabelsForDocument(
if (!timelines) return labels;
for (const timeline of Object.values(timelines) as Array<TimelineWithLabels | undefined>) {
const timelineLabels = timeline?.getLabels?.() ?? timeline?.labels ?? {};
for (const label of Object.keys(timelineLabels)) {
for (const label of Object.keys(labelsOf(timeline))) {
const pair = transitionParts(label);
if (!pair) continue;
const outgoing = findTimedElement(doc, pair[0]);