Skip to content

Commit 165be85

Browse files
fix(cli): timeline split keeps a sub-composition's place in both halves (#5410)
1 parent 76f8a56 commit 165be85

6 files changed

Lines changed: 40 additions & 11 deletions

File tree

‎packages/cli/src/timeline/timeline.e2e.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ describe("timeline edit command", () => {
190190
}
191191
});
192192

193+
it("keeps a sub-composition's place in both halves of a split", () => {
194+
const dir = mkdtempSync(join(tmpdir(), "hf-timeline-split-host-"));
195+
try {
196+
writeFileSync(
197+
join(dir, "index.html"),
198+
`<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>`,
199+
);
200+
writeFileSync(
201+
join(dir, "sub.html"),
202+
`<div data-composition-id="sub" data-duration="4"><div id="inner" data-start="0" data-duration="4"></div></div>`,
203+
);
204+
const result = run(dir, "split", "#host", "3");
205+
expect(result.status, result.stderr).toBe(0);
206+
const html = readFileSync(join(dir, "index.html"), "utf8");
207+
const tag = (id: string) => html.match(new RegExp(`<[^>]*\\sid="${id}"[^>]*>`))?.[0];
208+
expect(tag("host")).toContain('data-playback-start="0"');
209+
expect(tag("host-2")).toContain('data-playback-start="2"');
210+
} finally {
211+
rmSync(dir, { recursive: true, force: true });
212+
}
213+
});
214+
193215
it("uses the next free numeric split suffix on repeat", () => {
194216
const dir = project();
195217
try {

‎packages/studio-server/src/helpers/sourceMutation.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ export function splitElementInHtml(
394394
duration: number;
395395
playbackStart?: number;
396396
playbackRate?: number;
397-
stampPlaybackStart?: boolean;
398397
// The element's current resolved track (authored, or the runtime's
399398
// positional-index fallback when unauthored). Stamped onto both halves so
400399
// inserting the clone can't shift either one to a different row — see
@@ -438,14 +437,14 @@ export function splitElementInHtml(
438437
// Keep the "clip" class — the runtime uses it to control visibility
439438
// based on data-start/data-duration timing.
440439

441-
// A split creates two views over the same media source. Even an untrimmed
442-
// audio/video element needs an explicit zero in-point stamped on the first
440+
// A split creates two views over the same media source or sub-composition.
441+
// Even an untrimmed one needs an explicit zero in-point stamped on the first
443442
// half so the second half can advance from it instead of restarting at zero.
444443
const playbackStartAttr = el.hasAttribute("data-playback-start")
445444
? "data-playback-start"
446445
: el.hasAttribute("data-media-start")
447446
? "data-media-start"
448-
: fallbackTiming?.stampPlaybackStart
447+
: el.matches("[data-composition-src], [data-composition-id]")
449448
? "data-playback-start"
450449
: el.matches("audio, video")
451450
? "data-media-start"

‎packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,26 @@ describe("splitElementInHtml", () => {
196196
expect(result.html).not.toContain("data-playback-start");
197197
});
198198

199+
it.each(['data-composition-src="scene.html"', 'data-composition-id="scene"'])(
200+
"stamps an in-point on both halves of a sub-composition host (%s)",
201+
(host) => {
202+
const hostSource = source.replace('id="box"', `id="box" ${host}`);
203+
const { document } = parseHTML(
204+
splitElementInHtml(hostSource, { id: "box" }, 3, "box-split").html,
205+
);
206+
207+
expect(document.getElementById("box")?.getAttribute("data-playback-start")).toBe("0");
208+
expect(document.getElementById("box-split")?.getAttribute("data-playback-start")).toBe("2");
209+
},
210+
);
211+
199212
it("stamps a legacy composition offset and advances the second half by playback rate", () => {
200-
const result = splitElementInHtml(source, { id: "box" }, 3, "box-split", {
213+
const hostSource = source.replace('id="box"', 'id="box" data-composition-src="scene.html"');
214+
const result = splitElementInHtml(hostSource, { id: "box" }, 3, "box-split", {
201215
start: 1,
202216
duration: 6,
203217
playbackStart: 1.5,
204218
playbackRate: 2,
205-
stampPlaybackStart: true,
206219
});
207220

208221
const { document } = parseHTML(result.html);

‎packages/studio-server/src/routes/files.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ function postCutBatch(
114114
elementDuration: number;
115115
playbackStart?: number;
116116
playbackRate?: number;
117-
isComposition?: boolean;
118117
}>;
119118
}>,
120119
): Promise<Response> {

‎packages/studio-server/src/routes/files.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ interface AtomicCutTarget {
289289
elementDuration: number;
290290
playbackStart?: number;
291291
playbackRate?: number;
292-
isComposition?: boolean;
293292
track?: number;
294293
}
295294

@@ -2606,7 +2605,6 @@ async function foldAtomicCutFile(
26062605
duration: cut.elementDuration,
26072606
playbackStart: cut.playbackStart,
26082607
playbackRate: cut.playbackRate,
2609-
stampPlaybackStart: cut.isComposition,
26102608
track: cut.track,
26112609
});
26122610
if (!split.matched || !split.newId) {

‎packages/studio/src/utils/razorSplitTransaction.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ interface CutTarget {
1818
elementDuration: number;
1919
playbackStart?: number;
2020
playbackRate?: number;
21-
isComposition?: boolean;
2221
track?: number;
2322
}
2423

@@ -71,7 +70,6 @@ function buildCutTarget(
7170
elementDuration: element.duration,
7271
...(element.playbackStart != null ? { playbackStart: element.playbackStart } : {}),
7372
...(element.playbackRate != null ? { playbackRate: element.playbackRate } : {}),
74-
...(element.kind === "composition" ? { isComposition: true } : {}),
7573
// Pin both halves to the current track: unstamped, the runtime's positional
7674
// fallback (parseAuthoredTrack) renumbers the new sibling onto a new row.
7775
track: resolveElementTrack(element),

0 commit comments

Comments
 (0)