Skip to content

Commit 400bbe1

Browse files
committed
refactor(studio): stacking sync comments match the moved-clip-only rule
Drops the stale cascade wording, checks the time overlap before the paint-scope string compare, and every test case names its move direction.
1 parent 4e77ded commit 400bbe1

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎packages/studio/src/player/components/timelineStackingSync.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function el(
2222
function patchMap(
2323
elements: StackingElement[],
2424
edited: string[],
25-
direction: StackingDirection = "up",
25+
direction: StackingDirection,
2626
): Record<string, number> {
2727
const out: Record<string, number> = {};
2828
for (const p of computeStackingPatches(elements, edited, direction)) out[p.key] = p.zIndex;
@@ -63,7 +63,7 @@ describe("stacking-context partitioning", () => {
6363
stackingContextId: null,
6464
};
6565

66-
expect(patchMap([root, scene], ["root"])).toEqual({});
66+
expect(patchMap([root, scene], ["root"], "up")).toEqual({});
6767
});
6868

6969
it("never compares or patches across stacking contexts", () => {
@@ -91,7 +91,7 @@ describe("stacking-context partitioning", () => {
9191
};
9292
// X edited: only same-context neighbours participate — none here, so X keeps
9393
// its z (nothing to fix WITHIN its context) and Y is never touched.
94-
expect(patchMap([x, y], ["x"])).toEqual({});
94+
expect(patchMap([x, y], ["x"], "up")).toEqual({});
9595
});
9696

9797
it("still resolves within the edited clip's own context", () => {
@@ -120,7 +120,7 @@ describe("stacking-context partitioning", () => {
120120
// by flipping z so a MUST be lifted).
121121
const aWrong = { ...a, track: 0, zIndex: 1 };
122122
const bLow = { ...b, track: 1, zIndex: 5 };
123-
const patches = patchMap([aWrong, bLow], ["a"]);
123+
const patches = patchMap([aWrong, bLow], ["a"], "up");
124124
expect(patches.a).toBeGreaterThan(5);
125125
});
126126
});
@@ -137,7 +137,7 @@ describe("computeStackingPatches", () => {
137137
it("no overlapping clips → no patch", () => {
138138
// a (0..5 on track 0) and b (10..15 on track 1) never overlap in time.
139139
const elements = [el("a", 0, 0, 5, 10), el("b", 1, 10, 5, 5)];
140-
expect(patchMap(elements, ["a"])).toEqual({});
140+
expect(patchMap(elements, ["a"], "up")).toEqual({});
141141
});
142142

143143
it("moved up with z too low → raised above the clip it now sits above", () => {

‎packages/studio/src/player/components/timelineStackingSync.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface StackingElement {
3838
* (e.g. an unmounted / nested sub-comp element, or one outside the active file).
3939
* A non-finite-z clip is EXCLUDED from the computation — it is neither a stacking
4040
* neighbour nor resolvable as an edit — so an unresolved node never fabricates a
41-
* z=0 neighbour that poisons the boundary math (item 13). The reader signals a
41+
* z=0 neighbour. The reader signals a
4242
* miss with NaN rather than null so the value stays assignable to the existing
4343
* `(el) => number` reader contract the drag hook / commit deps declare.
4444
*/
@@ -57,10 +57,9 @@ export interface StackingElement {
5757
/**
5858
* Discovery / DOM document position (optional). Two clips with EQUAL z paint by
5959
* DOM order — the one LATER in the DOM paints ON TOP. When supplied, "is A above
60-
* B" uses (zIndex, domIndex); without it equal-z is ambiguous and the sync can
61-
* under-patch (the reported bug: a clip dragged to the bottom lane over an
62-
* equal-z neighbour changed nothing on canvas). Callers pass the index of the
63-
* element in the discovery order array.
60+
* B" uses (zIndex, domIndex); without it equal z counts as "not above", so the
61+
* move writes a z. Callers pass the index of the element in the discovery order
62+
* array.
6463
*/
6564
domIndex?: number;
6665
}
@@ -74,7 +73,7 @@ export interface StackingPatch {
7473
/**
7574
* Canonical paint-scope key: leaf z-indexes are comparable only within the same
7675
* source document and CSS stacking context. The ONLY place this normalization
77-
* lives — partitioning, membership checks, and pairwise equality all use it.
76+
* lives; samePaintScope compares with it.
7877
*/
7978
const paintScopeKey = (el: { sourceFile?: string; stackingContextId?: string | null }): string =>
8079
JSON.stringify([el.sourceFile ?? null, el.stackingContextId ?? null]);
@@ -169,7 +168,7 @@ export function computeStackingPatches(
169168
const patches: StackingPatch[] = [];
170169
for (const clip of edited) {
171170
const overlapping = live.filter(
172-
(o) => o.key !== clip.key && samePaintScope(clip, o) && overlapsInTime(clip, o),
171+
(o) => o.key !== clip.key && overlapsInTime(clip, o) && samePaintScope(clip, o),
173172
);
174173
const zIndex = direction === "up" ? raisedZ(clip, overlapping) : loweredZ(clip, overlapping);
175174
if (zIndex === null) continue;

‎packages/studio/src/player/components/useTimelineStackingSync.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function useTimelineStackingSync({
5555
// NaN (NOT 0) when the element can't be resolved in the preview iframe — a
5656
// nested / unmounted sub-comp node, or one outside the active file. Fabricating
5757
// z=0 would enter computeStackingPatches as a real overlapping neighbour at the
58-
// z-floor and skew the boundary math; a non-finite value tells it to EXCLUDE this
58+
// z-floor; a non-finite value tells it to EXCLUDE this
5959
// clip instead. NaN (rather than null) keeps the return assignable to the
6060
// `(el) => number` reader contract the drag hook / commit deps declare.
6161
const readClipZIndex = useCallback(

0 commit comments

Comments
 (0)