fix(studio): a sealed motion path stays on its layer after a seek (#8679)

* test(studio): sealed motion path waits for the frame's x/y

* fix(studio): a sealed motion path waits for the frame's x/y before drawing

* test(studio): a sealed motion path drops when the selection moves before the read lands

* fix(studio): a sealed motion path is kept only for the layer it was drawn for
This commit is contained in:
Miguel Ángel
2026-11-24 09:40:55 +00:00
committed by GitHub
parent fb1b15b941
commit efb797abbf
2 changed files with 82 additions and 1 deletions
@@ -70,6 +70,78 @@ it("draws an axis the tween leaves alone where GSAP renders it, so the playhead
}
});
/** A frame whose window Studio cannot reach, as a sealed preview's. */
function sealedIframe(): HTMLIFrameElement {
const iframe = document.createElement("iframe");
const blocked = new Proxy(
{},
{
get: () => {
throw new DOMException("blocked", "SecurityError");
},
},
);
Object.defineProperty(iframe, "contentWindow", { value: blocked });
return iframe;
}
// fails without the fix: before a sealed frame's x/y read landed, the path drew its y axis at 0.
it("waits for a sealed frame's x/y before drawing the axis the tween leaves alone", () => {
runtime.read = {
keyframes: [
{ percentage: 66.667, properties: { x: 60 } },
{ percentage: 100, properties: { x: 120 } },
],
};
const iframe = sealedIframe();
let points: string | undefined;
function Probe() {
const ref = useRef(iframe);
points = useMotionPathData(ref, "#box").geometry?.points;
return null;
}
const root = createRoot(document.body.appendChild(document.createElement("div")));
try {
act(() => root.render(<Probe />));
expect(points).toBeUndefined();
runtime.gsapPosition = { x: 60, y: 30 };
act(() => vi.advanceTimersByTime(250));
expect(points).toBe("60,30 120,30");
} finally {
act(() => root.unmount());
}
});
// fails without the fix: a path kept while the read was pending stayed drawn after the selection moved on.
it("drops the kept path when another layer is selected before a sealed read lands", () => {
runtime.read = {
keyframes: [
{ percentage: 66.667, properties: { x: 60 } },
{ percentage: 100, properties: { x: 120 } },
],
};
runtime.gsapPosition = { x: 60, y: 30 };
const iframe = sealedIframe();
let points: string | undefined;
function Probe({ selector }: { selector: string }) {
const ref = useRef(iframe);
points = useMotionPathData(ref, selector).geometry?.points;
return null;
}
const root = createRoot(document.body.appendChild(document.createElement("div")));
try {
act(() => root.render(<Probe selector="#a" />));
expect(points).toBe("60,30 120,30");
runtime.gsapPosition = null;
act(() => root.render(<Probe selector="#b" />));
expect(points).toBeUndefined();
} finally {
act(() => root.unmount());
}
});
it("reads no layout per frame until there is a path or a create ring to draw", () => {
const iframe = document.createElement("iframe");
document.body.append(iframe);
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState, type RefObject } from "react";
import { isHtmlElement } from "@hyperframes/core/runtime/dom-realm";
import { readRuntimeKeyframes } from "../../hooks/gsapRuntimeKeyframes";
import { readGsapPositionFromIframe } from "../../hooks/gsapPositionDetection";
import { useGsapSnapshotVersion } from "../../hooks/gsapFrameSnapshot";
import { elementHome, transformWDivisor } from "@hyperframes/core/runtime/editing-port";
import { isElementVisibleForOverlay } from "./domEditOverlayGeometry";
import {
@@ -26,6 +27,9 @@ function rectsClose(a: Rect, b: Rect): boolean {
const sealedPlugins = new WeakMap<HTMLIFrameElement, boolean>();
const sealedReadPending = (iframe: HTMLIFrameElement | null) =>
!!iframe && previewFrameOpaque(iframe);
export function hasMotionPathPlugin(iframe: HTMLIFrameElement | null): boolean {
if (iframe && previewFrameOpaque(iframe)) return sealedPlugins.get(iframe) ?? false;
try {
@@ -84,6 +88,7 @@ export function useMotionPathData(
} {
const [rect, setRect] = useState<Rect | null>(null);
const [geometry, setGeometry] = useState<MotionPathGeometry | null>(null);
const snapshotVersion = useGsapSnapshotVersion();
const resolvedForRef = useRef<string | null>(null);
const geometryResolved = resolvedForRef.current === selector;
const [visibleInPreview, setVisibleInPreview] = useState(true);
@@ -180,6 +185,10 @@ export function useMotionPathData(
// Position-only: never let a co-located size/scale tween shadow the path.
const read = readRuntimeKeyframes(iframeRef.current, selector, undefined, ["x", "y"]);
const base = read ? readGsapPositionFromIframe(iframeRef.current, selector) : null;
if (read && !base && sealedReadPending(iframeRef.current)) {
if (resolvedForRef.current !== selector) setGeometry(null);
return;
}
const next = buildMotionPathGeometry(read, base ?? undefined);
setGeometry((prev) =>
prev?.kind === next?.kind &&
@@ -192,7 +201,7 @@ export function useMotionPathData(
recompute();
const id = window.setInterval(recompute, 250);
return () => window.clearInterval(id);
}, [selector, iframeRef]);
}, [selector, iframeRef, snapshotVersion]);
return { rect, geometry, geometryResolved, visibleInPreview, home, pScale };
}