Skip to content

Commit 0e86e64

Browse files
committed
fix(core): stop the runtime stamping timing onto an <hf-audio-group> bus
Where the phantom rows came from. The runtime stamps `data-start="0"` and `data-duration=<whole composition>` on every id'd child of the composition root "so they appear in the timeline even without animations" (init.ts, the `window.parent !== window` block). Its only skips were SCRIPT / STYLE / LINK, so an `<hf-audio-group>` got stamped too — which made it match the clip-manifest selector `[data-start], …`, so the bus entered `__clipManifest` as `kind: "element"`, `tagName: "hf-audio-group"`, 0 → 40s, and the studio drew it as an ordinary full-width clip row directly above the real group header. Observed on audio-real: 18 timeline elements, two of them `Voiceover|voiceover|hf-audio-group|manifest|0-40.0` and the same for `sfx`. 16 after this change, and the group rows and FX rack are unaffected. That row was draggable, trimmable and DELETABLE, and deleting it deletes the bus element — which is why deleting it took the group's automation lanes and its FX rack with it. Nothing was corrupted; the rack's subject was gone. `isTimelineIgnoredElement` in studio already excluded the tag with this exact reasoning, but it only guards the DOM-scan and implicit-layer paths. The bus arrived through the manifest, upstream of all of them, so the guard never saw it. Fixed at the source instead: both stamp loops now skip the tag. Not fixed: the `Stage` row in the same screenshot. That one is a real implicit layer for `<div class="stage">` — a visual container the author wrote — and it belongs in the timeline. `data-hf-ignore` on such a wrapper suppresses its row. Regression test asserts the bus keeps no timing while an id'd sibling still gets stamped; verified it fails on a revert. It has to stage `window.parent !== window` because the stamp only runs inside the studio preview, and it lives inside the `initSandboxRuntimeModular` describe so it gets the DOM reset — outside it, a previous test's leftover root wins `resolveRootCompositionElement()` and nothing is stamped at all, which reads as a pass. core: 122 files, 2481 tests.
1 parent f464026 commit 0e86e64

2 files changed

Lines changed: 103 additions & 49 deletions

File tree

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

Lines changed: 93 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,6 @@ it("schedules WebAudio element gain from author volume without bridge volume", (
1111
expect(source).not.toMatch(/vol\s*\*\s*state\.bridgeVolume/);
1212
});
1313

14-
/**
15-
* `data-volume` is an authoring GAIN up to `MAX_AUDIO_GAIN` (12 dB ~ 3.98) —
16-
* `HTMLMediaElement.volume` accepts only 0..1. The bridge clamps its own
17-
* argument, but the PRODUCT `clipVolume * volume` was assigned unclamped, so a
18-
* clip authored above unity threw
19-
* `IndexSizeError: The volume provided (2.42103) is outside the range [0, 1]`
20-
* (2.42103 is the +7.68 dB fader stop) — and the throw aborted the loop, so
21-
* every media element after it kept its old volume too.
22-
*/
23-
it("clamps the native volume of an over-unity clip instead of throwing", () => {
24-
const root = document.createElement("div");
25-
root.setAttribute("data-composition-id", "main");
26-
root.setAttribute("data-root", "true");
27-
root.setAttribute("data-start", "0");
28-
root.setAttribute("data-duration", "10");
29-
root.setAttribute("data-width", "1920");
30-
root.setAttribute("data-height", "1080");
31-
document.body.appendChild(root);
32-
33-
const loud = document.createElement("audio");
34-
loud.setAttribute("data-start", "0");
35-
loud.setAttribute("data-duration", "10");
36-
loud.setAttribute("data-volume", "2.42103");
37-
loud.load = () => {};
38-
root.appendChild(loud);
39-
// Second element proves the throw took the whole sweep down with it, not just
40-
// the offending clip.
41-
const quiet = document.createElement("audio");
42-
quiet.setAttribute("data-start", "0");
43-
quiet.setAttribute("data-duration", "10");
44-
quiet.setAttribute("data-volume", "0.5");
45-
quiet.load = () => {};
46-
root.appendChild(quiet);
47-
48-
window.__timelines = { main: createMockTimeline(10) };
49-
initSandboxRuntimeModular();
50-
51-
const errors: string[] = [];
52-
const onError = (e: ErrorEvent) => errors.push(String(e.message ?? e.error));
53-
window.addEventListener("error", onError);
54-
window.dispatchEvent(
55-
new MessageEvent("message", {
56-
data: { source: "hf-parent", type: "control", action: "set-volume", volume: 1 },
57-
}),
58-
);
59-
window.removeEventListener("error", onError);
60-
expect(errors).toEqual([]);
61-
});
62-
6314
function createMockTimeline(duration: number): RuntimeTimelineLike {
6415
const state = { time: 0, paused: true, duration };
6516
return {
@@ -208,6 +159,99 @@ describe("initSandboxRuntimeModular", () => {
208159
window.cancelAnimationFrame = originalCancelAnimationFrame;
209160
});
210161

162+
/**
163+
* `data-volume` is an authoring GAIN up to `MAX_AUDIO_GAIN` (12 dB ~ 3.98) —
164+
* `HTMLMediaElement.volume` accepts only 0..1. The bridge clamps its own
165+
* argument, but the PRODUCT `clipVolume * volume` was assigned unclamped, so a
166+
* clip authored above unity threw
167+
* `IndexSizeError: The volume provided (2.42103) is outside the range [0, 1]`
168+
* (2.42103 is the +7.68 dB fader stop) — and the throw aborted the loop, so
169+
* every media element after it kept its old volume too.
170+
*/
171+
it("clamps the native volume of an over-unity clip instead of throwing", () => {
172+
const root = document.createElement("div");
173+
root.setAttribute("data-composition-id", "main");
174+
root.setAttribute("data-root", "true");
175+
root.setAttribute("data-start", "0");
176+
root.setAttribute("data-duration", "10");
177+
root.setAttribute("data-width", "1920");
178+
root.setAttribute("data-height", "1080");
179+
document.body.appendChild(root);
180+
181+
const loud = document.createElement("audio");
182+
loud.setAttribute("data-start", "0");
183+
loud.setAttribute("data-duration", "10");
184+
loud.setAttribute("data-volume", "2.42103");
185+
loud.load = () => {};
186+
root.appendChild(loud);
187+
// Second element proves the throw took the whole sweep down with it, not just
188+
// the offending clip.
189+
const quiet = document.createElement("audio");
190+
quiet.setAttribute("data-start", "0");
191+
quiet.setAttribute("data-duration", "10");
192+
quiet.setAttribute("data-volume", "0.5");
193+
quiet.load = () => {};
194+
root.appendChild(quiet);
195+
196+
window.__timelines = { main: createMockTimeline(10) };
197+
initSandboxRuntimeModular();
198+
199+
const errors: string[] = [];
200+
const onError = (e: ErrorEvent) => errors.push(String(e.message ?? e.error));
201+
window.addEventListener("error", onError);
202+
window.dispatchEvent(
203+
new MessageEvent("message", {
204+
data: { source: "hf-parent", type: "control", action: "set-volume", volume: 1 },
205+
}),
206+
);
207+
window.removeEventListener("error", onError);
208+
expect(errors).toEqual([]);
209+
});
210+
211+
/**
212+
* The runtime stamps `data-start`/`data-duration` on every id'd child of the
213+
* composition root so a blank canvas still shows selectable rows. An
214+
* `<hf-audio-group>` is a mixer BUS, not a clip: stamping it put it in
215+
* `__clipManifest` as a full-duration element, which the studio drew as an
216+
* ordinary clip row above the real group header — draggable, trimmable, and
217+
* deletable, and deleting it takes the bus (so the group's FX rack) with it.
218+
*/
219+
it("does not stamp timing onto an <hf-audio-group> bus", () => {
220+
const root = document.createElement("div");
221+
root.setAttribute("data-composition-id", "main");
222+
root.setAttribute("data-root", "true");
223+
root.setAttribute("data-start", "0");
224+
root.setAttribute("data-duration", "10");
225+
root.setAttribute("data-width", "1920");
226+
root.setAttribute("data-height", "1080");
227+
document.body.appendChild(root);
228+
229+
const bus = document.createElement("hf-audio-group");
230+
bus.id = "voiceover";
231+
bus.setAttribute("data-label", "Voiceover");
232+
root.appendChild(bus);
233+
234+
// A plain id'd sibling proves the stamp still happens for everything else.
235+
const caption = document.createElement("div");
236+
caption.id = "cap-1";
237+
root.appendChild(caption);
238+
239+
window.__timelines = { main: createMockTimeline(10) };
240+
// The stamp only runs inside the studio preview (`window.parent !== window`),
241+
// which jsdom is not — so the condition has to be staged for the test.
242+
const realParent = window.parent;
243+
Object.defineProperty(window, "parent", { value: {}, configurable: true });
244+
try {
245+
initSandboxRuntimeModular();
246+
} finally {
247+
Object.defineProperty(window, "parent", { value: realParent, configurable: true });
248+
}
249+
250+
expect(bus.hasAttribute("data-start")).toBe(false);
251+
expect(bus.hasAttribute("data-duration")).toBe(false);
252+
expect(caption.getAttribute("data-start")).toBe("0");
253+
});
254+
211255
it("resolves Studio hold as a deterministic step at the segment end", () => {
212256
const defaultEase = (progress: number) => progress;
213257
const originalParseEase = vi.fn(() => defaultEase);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,14 @@ export function initSandboxRuntimeModular(): void {
14611461
// scene container we auto-stamp below (e.g. an opacity-crossfaded scene)
14621462
// must NOT suppress its own animated children — otherwise those children
14631463
// never become timeline clips and that scene can't inline-expand.
1464+
// A bus is not a clip. `<hf-audio-group>` carries a group's label, fader,
1465+
// mute and FX chain and has no timing of its own, so stamping it put it in
1466+
// `__clipManifest` as a full-duration element — which the studio drew as an
1467+
// ordinary clip row above the real group header. That row was draggable,
1468+
// trimmable and deletable, and deleting it removed the bus, taking the
1469+
// group's automation lanes and FX rack with it.
1470+
const isAudioGroupBus = (el: Element): boolean =>
1471+
el.tagName.toLowerCase() === HF_AUDIO_GROUP_TAG;
14641472
const authoredTimed = new Set<Element>(document.querySelectorAll("[data-start]"));
14651473
const hasAuthoredTimedAncestor = (element: HTMLElement): boolean => {
14661474
let node = element.parentElement;
@@ -1479,6 +1487,7 @@ export function initSandboxRuntimeModular(): void {
14791487
for (const target of child.targets()) {
14801488
if (!(target instanceof HTMLElement)) continue;
14811489
if (target === rootComp) continue;
1490+
if (isAudioGroupBus(target)) continue;
14821491
if (target.hasAttribute("data-start")) continue;
14831492
if (hasAuthoredTimedAncestor(target)) continue;
14841493
if (seen.has(target)) continue;
@@ -1506,6 +1515,7 @@ export function initSandboxRuntimeModular(): void {
15061515
if (hasAuthoredTimedAncestor(el)) continue;
15071516
if (seen.has(el)) continue;
15081517
if (el.tagName === "SCRIPT" || el.tagName === "STYLE" || el.tagName === "LINK") continue;
1518+
if (isAudioGroupBus(el)) continue;
15091519
seen.add(el);
15101520
el.setAttribute("data-start", "0");
15111521
el.setAttribute("data-duration", dur);

0 commit comments

Comments
 (0)