From 5d4420fee1bae9ca9cd0b157e33c7de2680be906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 22 Nov 2026 15:24:10 +0000 Subject: [PATCH] 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 --- packages/core/src/runtime/timeline.test.ts | 28 +++++++++++++++++++ packages/core/src/runtime/transitionLabels.ts | 11 ++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/core/src/runtime/timeline.test.ts b/packages/core/src/runtime/timeline.test.ts index e6d003eaf2..ab7227bbb7 100644 --- a/packages/core/src/runtime/timeline.test.ts +++ b/packages/core/src/runtime/timeline.test.ts @@ -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 = ` +
+
`; + 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"); diff --git a/packages/core/src/runtime/transitionLabels.ts b/packages/core/src/runtime/transitionLabels.ts index 13c9e21bb0..3eccf0089e 100644 --- a/packages/core/src/runtime/transitionLabels.ts +++ b/packages/core/src/runtime/transitionLabels.ts @@ -26,6 +26,14 @@ function findTimedElement(doc: Document, markerId: string): Element | null { ); } +function labelsOf(timeline: TimelineWithLabels | undefined): Record { + try { + return timeline?.getLabels?.() ?? timeline?.labels ?? {}; + } catch { + return {}; + } +} + export function transitionLabelsForDocument( doc: Document, timelines: Readonly> | undefined, @@ -34,8 +42,7 @@ export function transitionLabelsForDocument( if (!timelines) return labels; for (const timeline of Object.values(timelines) as Array) { - 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]);