fix(studio): realm-safe isHTMLElement so timeline z-index commits land

applyTimelineStackingReorder resolves the live clip from the preview IFRAME,
then gated it with `element instanceof HTMLElement` against the MAIN window's
constructor. Cross-realm instanceof is always false, so every timeline z-index
commit silently bailed ("element not live in iframe") — the drag resolved the
right z but never wrote it. Use the element's own-realm HTMLElement constructor
(matching timelineDOM.ts). Verified end-to-end: dragging a card down now lowers
its z-index and reorders the row, leaving sibling z-indexes untouched.

Unit tests missed this because the happy-dom test iframe shares a realm; caught
via a real-browser Puppeteer E2E drag.
This commit is contained in:
Miguel Angel Simon Sierra
2026-07-08 23:46:25 -04:00
parent e5ed512529
commit eef500c890
@@ -12,7 +12,12 @@ import type { EditHistoryKind } from "../utils/editHistory";
import type { TimelineZIndexReorderCommit } from "./useTimelineEditingTypes";
function isHTMLElement(element: Element | null): element is HTMLElement {
return element != null && element instanceof HTMLElement;
if (!element) return false;
// Use the element's OWN realm's HTMLElement: timeline clips live in the preview
// iframe, and cross-realm `element instanceof HTMLElement` (main window) is
// always false — which silently dropped every timeline z-index commit.
const Ctor = element.ownerDocument?.defaultView?.HTMLElement ?? globalThis.HTMLElement;
return element instanceof Ctor;
}
/**