diff --git a/packages/studio/src/player/lib/timelineDOM.test.ts b/packages/studio/src/player/lib/timelineDOM.test.ts index 378462459..7d29b70e5 100644 --- a/packages/studio/src/player/lib/timelineDOM.test.ts +++ b/packages/studio/src/player/lib/timelineDOM.test.ts @@ -102,6 +102,40 @@ describe("parseTimelineFromDOM — hfId from data-hf-id", () => { expect(element.hidden).toBe(true); }); + + it("captures the effective z-index from the live element, not the runtime inline-only value", () => { + // The runtime reports inline-only z-index (0 for CSS-rule authored z-index), + // which must NOT override the live element's effective z-index — otherwise + // the timeline collapses every CSS-styled clip to a z=0 tie and mis-orders. + const doc = makeDoc(` +
+
+
+ `); + const hostEl = doc.getElementById("hero"); + + const element = createTimelineElementFromManifestClip({ + clip: { + id: "hero", + label: "Hero", + kind: "element", + tagName: "div", + start: 0, + duration: 5, + track: 0, + zIndex: 0, + compositionId: null, + parentCompositionId: null, + compositionSrc: null, + assetUrl: null, + }, + fallbackIndex: 0, + doc, + hostEl, + }); + + expect(element.zIndex).toBe(30); + }); }); describe("createImplicitTimelineLayersFromDOM — hfId from data-hf-id", () => { diff --git a/packages/studio/src/player/lib/timelineDOM.ts b/packages/studio/src/player/lib/timelineDOM.ts index a90faec9d..968931097 100644 --- a/packages/studio/src/player/lib/timelineDOM.ts +++ b/packages/studio/src/player/lib/timelineDOM.ts @@ -155,7 +155,11 @@ export function createTimelineElementFromManifestClip(params: { start: clip.start, duration: clip.duration, track: clip.track, - zIndex: clip.zIndex ?? getTimelineElementZIndex(hostEl), + // Prefer the effective (computed) z-index read from the live element — the + // same read the reorder commit uses — so CSS-rule z-index (not just inline) + // is captured. clip.zIndex from the runtime is inline-only (0 for CSS rules), + // so it can only serve as a fallback when the element isn't live. + zIndex: getTimelineElementZIndex(hostEl) ?? clip.zIndex ?? 0, stackingContextId, parentCompositionId, compositionAncestors,