Skip to content

Commit acad7b2

Browse files
committed
fix(studio): keep every host row on the drill path, not just the top
Drilling two levels deep spared only the top-level row, so the middle host lost its row and its keyframe lane with it. Spare every host between the drilled one and the top, and anchor the children under the deepest host that actually has a row. Also stops resolveClipTimingBasis handing back a main-timeline start when a clip names a parent composition that is absent from the element list. The mount is unknowable there, so the child's own window is the only safe frame.
1 parent d48440a commit acad7b2

4 files changed

Lines changed: 106 additions & 5 deletions

File tree

‎packages/studio/src/hooks/gsapShared.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,31 @@ describe("resolveClipTimingBasis", () => {
217217
});
218218
});
219219

220+
it("treats a child whose parent composition is missing as starting at 0", () => {
221+
// The mount is unknowable, so the only safe frame is the child's own. The
222+
// old `?? 0` handed back `start` unchanged, which is a main-timeline value
223+
// masquerading as a composition-local one and caches negative percentages.
224+
const pill = {
225+
id: "pill",
226+
domId: "pill",
227+
start: 7,
228+
duration: 3,
229+
parentCompositionId: "not-in-elements",
230+
};
231+
expect(resolveClipTimingBasis("pill", "scene.html", [pill], [])).toEqual({
232+
elStart: 0,
233+
elDuration: 3,
234+
});
235+
});
236+
237+
it("keeps a main-timeline clip's own start when it names no parent", () => {
238+
const box = { id: "box", domId: "box", start: 4, duration: 2 };
239+
expect(resolveClipTimingBasis("box", "index.html", [box], [])).toEqual({
240+
elStart: 4,
241+
elDuration: 2,
242+
});
243+
});
244+
220245
it("falls back to a unit window when neither the element nor a host resolves", () => {
221246
expect(resolveClipTimingBasis("ghost", "index.html", [], [])).toEqual({
222247
elStart: 0,

‎packages/studio/src/hooks/gsapShared.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,16 @@ export function resolveClipTimingBasis(
299299
const parent = parentId
300300
? elements.find((el) => el.domId === parentId || el.id === parentId)
301301
: undefined;
302-
const mount = direct.expandedParentStart ?? parent?.start ?? 0;
303-
return { elStart: direct.start - mount, elDuration: direct.duration };
302+
const mount = direct.expandedParentStart ?? parent?.start;
303+
if (mount !== undefined) return { elStart: direct.start - mount, elDuration: direct.duration };
304+
// No parent composition named, so this IS a main-timeline clip and its own
305+
// start is already the basis.
306+
if (!parentId) return { elStart: direct.start, elDuration: direct.duration };
307+
// It named a parent we cannot find, so the mount is unknowable. Its tweens
308+
// are still composition-local, so treat its own window as the frame rather
309+
// than subtracting nothing and handing back a main-timeline start, which is
310+
// exactly the mixed-frame subtraction this function exists to prevent.
311+
return { elStart: 0, elDuration: direct.duration };
304312
}
305313
const hostId = domClipChildren.find((c) => c.id === elementId)?.hostId;
306314
const host = hostId

‎packages/studio/src/player/hooks/useExpandedTimelineElements.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,51 @@ describe("buildExpandedElements", () => {
143143
expect(child.sourceFile).toBe("c.html"); // C's file, not b.html or a.html
144144
});
145145

146+
it("keeps the middle host's row when drilling two levels deep", () => {
147+
// A embeds B; C lives in B. Drilling into B must leave BOTH host rows
148+
// standing: sparing only the top-level one drops B's row, and its keyframe
149+
// lane goes with it because diamonds render per row.
150+
const elements = [
151+
el({ id: "A", domId: "A", start: 10, duration: 8, compositionSrc: "a.html" }),
152+
el({ id: "B", domId: "B", start: 12, duration: 4, track: 1, compositionSrc: "b.html" }),
153+
];
154+
const manifest = [
155+
clip({ id: "A", start: 10, duration: 8, compositionSrc: "a.html" }),
156+
clip({ id: "B", start: 12, duration: 4, compositionSrc: "b.html" }),
157+
clip({ id: "C", start: 13, duration: 2 }),
158+
];
159+
const parentMap = new Map([
160+
["B", "A"],
161+
["C", "B"],
162+
]);
163+
164+
const out = buildExpandedElements(elements, manifest, parentMap, "A", "B");
165+
const rows = out.map((e) => e.domId ?? e.id);
166+
expect(rows).toContain("B");
167+
// The child sits under its own host, not under the top-level row.
168+
expect(rows.indexOf("C")).toBeGreaterThan(rows.indexOf("B"));
169+
});
170+
171+
it("still drills a host that exists only in the manifest, without a row for it", () => {
172+
// Same shape, but B has no store element, so there is no row to spare. The
173+
// children stay anchored to the top-level row rather than vanishing.
174+
const elements = [
175+
el({ id: "A", domId: "A", start: 10, duration: 8, compositionSrc: "a.html" }),
176+
];
177+
const manifest = [
178+
clip({ id: "A", start: 10, duration: 8, compositionSrc: "a.html" }),
179+
clip({ id: "B", start: 12, duration: 4, compositionSrc: "b.html" }),
180+
clip({ id: "C", start: 13, duration: 2 }),
181+
];
182+
const parentMap = new Map([
183+
["B", "A"],
184+
["C", "B"],
185+
]);
186+
187+
const out = buildExpandedElements(elements, manifest, parentMap, "A", "B");
188+
expect(out.map((e) => e.domId ?? e.id)).toEqual(["A", "C"]);
189+
});
190+
146191
// Regression: an expanded child must share one identity (`key`) with the flat
147192
// store element for the same DOM id. Before the fix the child key fell back to
148193
// the colon form (`index.html:eyebrow:N`) while the store/selection used the

‎packages/studio/src/player/hooks/useExpandedTimelineElements.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,39 @@ export function buildExpandedElements(
284284
);
285285
if (expanded.length === 0) return filterToTopLevel(elements, parentMap);
286286

287+
// Every host between the drilled one and the top level owns a row, so the
288+
// drill has to spare all of them, not just the top. A middle host is still a
289+
// host: dropping its row drops its keyframe lane with it.
290+
const drillPath = new Set<string>();
291+
for (let cursor: string | undefined = siblingParentId; cursor; ) {
292+
if (drillPath.has(cursor)) break;
293+
drillPath.add(cursor);
294+
if (cursor === topLevelId) break;
295+
cursor = parentMap.get(cursor);
296+
}
297+
// Children hang under the DEEPEST host on that path, so anchor them there
298+
// when it has a row of its own and fall back to the top-level row when it
299+
// does not (a host that lives only in the manifest never had one).
300+
const anchorsChildren = (el: TimelineElement): boolean =>
301+
drillPath.has(siblingParentId) && elements.some((e) => (e.domId ?? e.id) === siblingParentId)
302+
? (el.domId ?? el.id) === siblingParentId
303+
: (el.key ?? el.id) === parentKey;
304+
287305
// ADDITIVE drill-in: the host row stays and its children are appended under
288306
// it. Expansion is also triggered by the playhead alone (paused auto-expand),
289-
// so substituting the host row made it vanish on an ordinary seek — and with
307+
// so substituting the host row made it vanish on an ordinary seek, and with
290308
// it the host's keyframe lane, since diamonds render per row from
291309
// `keyframeCache.get(elementKey)`. The synthetic fractional lanes above sit
292310
// strictly between the host's lane and the next integer, so the children have
293311
// their own rows without the host having to give up its own.
294312
return elements
295-
.filter((el) => (el.key ?? el.id) === parentKey || !parentMap.has(el.domId ?? el.id))
296-
.flatMap((el) => ((el.key ?? el.id) === parentKey ? [el, ...expanded] : [el]));
313+
.filter(
314+
(el) =>
315+
(el.key ?? el.id) === parentKey ||
316+
drillPath.has(el.domId ?? el.id) ||
317+
!parentMap.has(el.domId ?? el.id),
318+
)
319+
.flatMap((el) => (anchorsChildren(el) ? [el, ...expanded] : [el]));
297320
}
298321

299322
export function useExpandedTimelineElements(): TimelineElement[] {

0 commit comments

Comments
 (0)