Skip to content

Commit b20d0a6

Browse files
fix(studio): a split at a clip's edge leaves the file unchanged (#6826)
* fix(studio): a split at a clip's edge leaves the file unchanged * fix(studio): keep the split margin's doc within the comment width * chore(studio-server): keep the split margin's comments within the file's share
1 parent 88d8e5b commit b20d0a6

4 files changed

Lines changed: 43 additions & 10 deletions

File tree

‎packages/parsers/src/compositionContract.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
export const COMPOSITION_CONTRACT_VERSION = 1 as const;
1010

11+
/** Least a split leaves either side of its cut (s); timing is written to the ms, so less rounds to a 0-length half. */
12+
export const SPLIT_BOUNDARY_EPSILON_S = 0.03;
13+
1114
export const COMPOSITION_ATTRIBUTES = Object.freeze({
1215
start: "data-start",
1316
duration: "data-duration",
@@ -222,11 +225,8 @@ function derivedEndsAreConsistent(parsedEnd: number, canonicalEnd: number): bool
222225
//
223226
// The compiler (`compileTimingAttrs` in @hyperframes/core) writes
224227
// `data-end = data-start + data-duration` into the bundled HTML so the runtime
225-
// can key off a single attribute. That derived attribute is legitimate — it is
226-
// not a legacy authoring shape. Treating it as `deprecated-end` here made the
227-
// linter fire `deprecated_data_end` on the compiler's own output whenever
228-
// StaticGuard re-validated a bundled composition, producing a false-positive
229-
// cluster reported in the field (n=25+ across cli-feedback crons 61-68).
228+
// can key off a single attribute. That derived attribute is not a legacy
229+
// authoring shape, so the compiler's own output is never flagged.
230230
//
231231
// We keep `deprecated-end` for the truly legacy shape (see `readLegacyEnd` —
232232
// `data-end` present without `data-duration`) and for the *conflicting* case

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
mintHfId,
1313
walkCompositionDescendants,
1414
} from "@hyperframes/parsers/hf-ids";
15-
import { readClipTiming, writeClipTiming } from "@hyperframes/core/composition-contract";
15+
import {
16+
readClipTiming,
17+
SPLIT_BOUNDARY_EPSILON_S,
18+
writeClipTiming,
19+
} from "@hyperframes/core/composition-contract";
1620
import { relinkSplitHalves } from "@hyperframes/core/media-link";
1721
import { parseStyleDecls, patchStyleAttrString } from "./sourceStyleMutation.js";
1822

@@ -455,7 +459,11 @@ export function splitElementInHtml(
455459
start = fallbackTiming.start;
456460
duration = fallbackTiming.duration;
457461
}
458-
if (duration <= 0 || splitTime <= start || splitTime >= start + duration) {
462+
if (
463+
duration <= 0 ||
464+
splitTime < start + SPLIT_BOUNDARY_EPSILON_S ||
465+
splitTime > start + duration - SPLIT_BOUNDARY_EPSILON_S
466+
) {
459467
return { html: source, matched: false, newId: null };
460468
}
461469

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ describe("splitElementInHtml — hfId clone isolation", () => {
2323
});
2424
});
2525

26+
// A second split at the same playhead: the first one wrote the left half's end rounded to the millisecond (2.346 for a
27+
// playhead at 2.3456), so the same cut lands a fraction inside that edge and its sliver rounded to data-duration="0".
28+
describe("splitElementInHtml — a cut at an existing edge", () => {
29+
const clip = (start: number, duration: number) =>
30+
`<html><body><div data-composition-id="root"><div id="a" class="clip" data-start="${start}" data-duration="${duration}"></div></div></body></html>`;
31+
const durations = (html: string) =>
32+
[...parseHTML(html).document.querySelectorAll(".clip")].map((el) =>
33+
Number(el.getAttribute("data-duration")),
34+
);
35+
36+
it("leaves the file as it was when the cut is within the split margin of either edge", () => {
37+
for (const at of [2.3456, 2.346, 1, 1.0004, 2.33]) {
38+
const source = clip(1, 1.346);
39+
const result = splitElementInHtml(source, { id: "a" }, at, "a-split");
40+
expect(result.matched, `a cut at ${at}`).toBe(false);
41+
expect(result.html, `a cut at ${at}`).toBe(source);
42+
}
43+
});
44+
45+
it("still cuts at the margin itself, and no half it writes is ever zero long", () => {
46+
const result = splitElementInHtml(clip(1, 1.346), { id: "a" }, 1.03, "a-split");
47+
expect(result.matched).toBe(true);
48+
expect(durations(result.html)).toEqual([0.03, 1.316]);
49+
});
50+
});
51+
2652
describe("splitElementInHtml", () => {
2753
const source = `<!DOCTYPE html><html><head><style>#box { position: absolute; top: 100px; background: red; }</style></head><body><div data-composition-id="root"><div id="box" class="clip" data-start="1" data-duration="6">Hello</div></div></body></html>`;
2854

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { SPLIT_BOUNDARY_EPSILON_S } from "@hyperframes/core/composition-contract";
12
import type { TimelineElement } from "../player/store/playerStore";
23

34
export { buildPatchTarget, readFileContent } from "../hooks/timelineEditingHelpers";
4-
5-
/** Minimum distance (seconds) from clip boundaries to allow a split. */
6-
export const SPLIT_BOUNDARY_EPSILON_S = 0.03;
5+
export { SPLIT_BOUNDARY_EPSILON_S };
76

87
/**
98
* True when splitTime leaves at least SPLIT_BOUNDARY_EPSILON_S on both sides

0 commit comments

Comments
 (0)