Skip to content

Write HTML. Render video. Built for agents.

fix(cli): timeline split keeps a sub-composition's place in both halves (#5410)

Miguel Ángel165be8513281
diff --git a/packages/cli/src/timeline/timeline.e2e.test.ts b/packages/cli/src/timeline/timeline.e2e.test.ts
index 5db67a9edc..5055690b7a 100644
--- a/packages/cli/src/timeline/timeline.e2e.test.ts
+++ b/packages/cli/src/timeline/timeline.e2e.test.ts
@@ -190,6 +190,28 @@ describe("timeline edit command", () => {
}
});
+ it("keeps a sub-composition's place in both halves of a split", () => {
+ const dir = mkdtempSync(join(tmpdir(), "hf-timeline-split-host-"));
+ try {
+ writeFileSync(
+ join(dir, "index.html"),
+ `<div data-composition-id="main" data-duration="12"><div id="host" data-composition-src="sub.html" data-start="1" data-duration="4" data-track-index="0"></div></div>`,
+ );
+ writeFileSync(
+ join(dir, "sub.html"),
+ `<div data-composition-id="sub" data-duration="4"><div id="inner" data-start="0" data-duration="4"></div></div>`,
+ );
+ const result = run(dir, "split", "#host", "3");
+ expect(result.status, result.stderr).toBe(0);
+ const html = readFileSync(join(dir, "index.html"), "utf8");
+ const tag = (id: string) => html.match(new RegExp(`<[^>]*\\sid="${id}"[^>]*>`))?.[0];
+ expect(tag("host")).toContain('data-playback-start="0"');
+ expect(tag("host-2")).toContain('data-playback-start="2"');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
it("uses the next free numeric split suffix on repeat", () => {
const dir = project();
try {
diff --git a/packages/studio-server/src/helpers/sourceMutation.ts b/packages/studio-server/src/helpers/sourceMutation.ts
index 457d7e3405..0c34562867 100644
--- a/packages/studio-server/src/helpers/sourceMutation.ts
+++ b/packages/studio-server/src/helpers/sourceMutation.ts
@@ -394,7 +394,6 @@ export function splitElementInHtml(
duration: number;
playbackStart?: number;
playbackRate?: number;
- stampPlaybackStart?: boolean;
// The element's current resolved track (authored, or the runtime's
// positional-index fallback when unauthored). Stamped onto both halves so
// inserting the clone can't shift either one to a different row — see
@@ -438,14 +437,14 @@ export function splitElementInHtml(
// Keep the "clip" class — the runtime uses it to control visibility
// based on data-start/data-duration timing.
- // A split creates two views over the same media source. Even an untrimmed
- // audio/video element needs an explicit zero in-point stamped on the first
+ // A split creates two views over the same media source or sub-composition.
+ // Even an untrimmed one needs an explicit zero in-point stamped on the first
// half so the second half can advance from it instead of restarting at zero.
const playbackStartAttr = el.hasAttribute("data-playback-start")
? "data-playback-start"
: el.hasAttribute("data-media-start")
? "data-media-start"
- : fallbackTiming?.stampPlaybackStart
+ : el.matches("[data-composition-src], [data-composition-id]")
? "data-playback-start"
: el.matches("audio, video")
? "data-media-start"
diff --git a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
index 47208de26e..966e8dba14 100644
--- a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
+++ b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
@@ -196,13 +196,26 @@ describe("splitElementInHtml", () => {
expect(result.html).not.toContain("data-playback-start");
});
+ it.each(['data-composition-src="scene.html"', 'data-composition-id="scene"'])(
+ "stamps an in-point on both halves of a sub-composition host (%s)",
+ (host) => {
+ const hostSource = source.replace('id="box"', `id="box" ${host}`);
+ const { document } = parseHTML(
+ splitElementInHtml(hostSource, { id: "box" }, 3, "box-split").html,
+ );
+
+ expect(document.getElementById("box")?.getAttribute("data-playback-start")).toBe("0");
+ expect(document.getElementById("box-split")?.getAttribute("data-playback-start")).toBe("2");
+ },
+ );
+
it("stamps a legacy composition offset and advances the second half by playback rate", () => {
- const result = splitElementInHtml(source, { id: "box" }, 3, "box-split", {
+ const hostSource = source.replace('id="box"', 'id="box" data-composition-src="scene.html"');
+ const result = splitElementInHtml(hostSource, { id: "box" }, 3, "box-split", {
start: 1,
duration: 6,
playbackStart: 1.5,
playbackRate: 2,
- stampPlaybackStart: true,
});
const { document } = parseHTML(result.html);
diff --git a/packages/studio-server/src/routes/files.test.ts b/packages/studio-server/src/routes/files.test.ts
index c3e6368147..dc01f1ba5b 100644
--- a/packages/studio-server/src/routes/files.test.ts
+++ b/packages/studio-server/src/routes/files.test.ts
@@ -114,7 +114,6 @@ function postCutBatch(
elementDuration: number;
playbackStart?: number;
playbackRate?: number;
- isComposition?: boolean;
}>;
}>,
): Promise<Response> {
diff --git a/packages/studio-server/src/routes/files.ts b/packages/studio-server/src/routes/files.ts
index 6e972b3c44..1703e53283 100644
--- a/packages/studio-server/src/routes/files.ts
+++ b/packages/studio-server/src/routes/files.ts
@@ -289,7 +289,6 @@ interface AtomicCutTarget {
elementDuration: number;
playbackStart?: number;
playbackRate?: number;
- isComposition?: boolean;
track?: number;
}
@@ -2606,7 +2605,6 @@ async function foldAtomicCutFile(
duration: cut.elementDuration,
playbackStart: cut.playbackStart,
playbackRate: cut.playbackRate,
- stampPlaybackStart: cut.isComposition,
track: cut.track,
});
if (!split.matched || !split.newId) {
diff --git a/packages/studio/src/utils/razorSplitTransaction.ts b/packages/studio/src/utils/razorSplitTransaction.ts
index bc139b7a2a..7f17d2f849 100644
--- a/packages/studio/src/utils/razorSplitTransaction.ts
+++ b/packages/studio/src/utils/razorSplitTransaction.ts
@@ -18,7 +18,6 @@ interface CutTarget {
elementDuration: number;
playbackStart?: number;
playbackRate?: number;
- isComposition?: boolean;
track?: number;
}
@@ -71,7 +70,6 @@ function buildCutTarget(
elementDuration: element.duration,
...(element.playbackStart != null ? { playbackStart: element.playbackStart } : {}),
...(element.playbackRate != null ? { playbackRate: element.playbackRate } : {}),
- ...(element.kind === "composition" ? { isComposition: true } : {}),
// Pin both halves to the current track: unstamped, the runtime's positional
// fallback (parseAuthoredTrack) renumbers the new sibling onto a new row.
track: resolveElementTrack(element),