diff --git a/packages/core/src/runtime/editing/gsapSnapshot.test.ts b/packages/core/src/runtime/editing/gsapSnapshot.test.ts
index d6d643844d..5e7147a05c 100644
--- a/packages/core/src/runtime/editing/gsapSnapshot.test.ts
+++ b/packages/core/src/runtime/editing/gsapSnapshot.test.ts
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it } from "vitest";
import { gsap as realGsap } from "gsap";
import { handleFor } from "../editingHandles";
+import { gestureStart } from "../editingGestureStart";
import { gsapSnapshot } from "./gsapSnapshot";
import { MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS } from "./gsapSnapshotLimits";
@@ -150,4 +151,17 @@ describe("gsapSnapshot", () => {
expect(snapshot.timelines[0]!.tweens).toHaveLength(1);
expect(snapshot.targets[0]!.values.x).toBeCloseTo(600);
});
+
+ it("leaves a CSS-moved element's position to CSS when only its opacity is tweened", async () => {
+ document.body.innerHTML = `
Title
`;
+ const title = document.getElementById("title")!;
+ const tl = realGsap.timeline({ paused: true });
+ tl.to("#title", { opacity: 0.5, duration: 10 }, 0);
+ tl.seek(0);
+ Object.assign(window, { gsap: realGsap, __timelines: { main: tl } });
+
+ await gsapSnapshot();
+
+ expect(gestureStart([handleFor(title)]).elements[0]!.gsap).toBeNull();
+ });
});
diff --git a/packages/core/src/runtime/editing/gsapSnapshot.ts b/packages/core/src/runtime/editing/gsapSnapshot.ts
index 84b5a8d929..862182c275 100644
--- a/packages/core/src/runtime/editing/gsapSnapshot.ts
+++ b/packages/core/src/runtime/editing/gsapSnapshot.ts
@@ -1,6 +1,7 @@
// The frame's GSAP tweens as plain data, for a parent that cannot reach the frame's window.
import type { EditingElementHandle } from "../editingElement";
import { handleFor } from "../editingHandles";
+import { MOVES, rendersTransform } from "../editingGestureStart";
import { isPlainRecord } from "../editingPort";
import { isElementNode } from "../domRealm";
import {
@@ -165,10 +166,14 @@ class SnapshotReader {
return [...this.channels].map(([element, channels]) => {
if (channels.size > MAX_SNAPSHOT_CHANNELS) throw new SnapshotBound("channels");
const values: Record = {};
- for (const channel of channels) {
+ const read = (channel: string) => {
const value = Number(gsap?.getProperty?.(element, channel));
if (Number.isFinite(value)) values[channel] = value;
- }
+ };
+ for (const channel of channels) read(channel);
+ const gsapOwnsPosition =
+ rendersTransform(element) || MOVES.some((channel) => channels.has(channel));
+ if (gsapOwnsPosition) for (const axis of ["x", "y"]) if (!(axis in values)) read(axis);
const className = element.getAttribute("class") ?? "";
if (className.length > MAX_SNAPSHOT_TEXT) throw new SnapshotBound("class names");
return { handle: handleFor(element), id: capped(element.id), className, values };
@@ -181,7 +186,7 @@ class SnapshotReader {
parsed: GsapSnapshotTween["parsed"],
parts: GsapSnapshotTween[],
) {
- const channels = this.channels.get(element) ?? new Set(["x", "y"]);
+ const channels = this.channels.get(element) ?? new Set();
this.channels.set(element, channels);
const steps = isPlainRecord(vars) ? [vars, ...stepsOf(vars.keyframes)] : [];
for (const step of steps)
diff --git a/packages/core/src/runtime/editingGestureStart.ts b/packages/core/src/runtime/editingGestureStart.ts
index 76ee497afd..47338d942b 100644
--- a/packages/core/src/runtime/editingGestureStart.ts
+++ b/packages/core/src/runtime/editingGestureStart.ts
@@ -125,7 +125,7 @@ type GsapWindow = {
// The channels Studio's move route and drag commit read as GSAP moving an element.
const POSITION = ["x", "y", "xPercent", "yPercent", "left", "top", "translateX", "translateY"];
-const MOVES = [...POSITION, "motionPath"];
+export const MOVES = [...POSITION, "motionPath"];
const TURNS = [
"rotation",
"rotationX",
@@ -162,7 +162,7 @@ function tweensOn(element: Element): GsapTween[] {
);
}
-const rendersTransform = (element: Element) =>
+export const rendersTransform = (element: Element) =>
!!(element as { _gsap?: { renderTransform?: unknown } })._gsap?.renderTransform;
export type EditingGestureBase = {
diff --git a/packages/studio/src/hooks/gsapSnapshotMoveRoute.browser.test.ts b/packages/studio/src/hooks/gsapSnapshotMoveRoute.browser.test.ts
new file mode 100644
index 0000000000..f1eb539075
--- /dev/null
+++ b/packages/studio/src/hooks/gsapSnapshotMoveRoute.browser.test.ts
@@ -0,0 +1,69 @@
+// Real Chrome: a CSS-placed element whose only tween is its opacity still moves by CSS once Studio has read GSAP.
+import { readFileSync } from "node:fs";
+import { createRequire } from "node:module";
+import type { Browser } from "puppeteer-core";
+import { afterAll, beforeAll, expect, it, vi } from "vitest";
+import { closeTestChrome, launchTestChrome } from "../../tests/chromeTestUtils";
+import { buildStudioBundle, openPreview, type Studio } from "../../tests/sealedPreviewHarness";
+
+vi.setConfig({ testTimeout: 60_000, hookTimeout: 60_000 });
+const require = createRequire(import.meta.url);
+const MODES = process.env.HF_PARITY_MODE ? [process.env.HF_PARITY_MODE] : ["unsealed", "sealed"];
+type Reads = Studio & {
+ settleGsapSnapshot: typeof import("./gsapFrameSnapshot").settleGsapSnapshot;
+ previewGestureStart: typeof import("../player/lib/previewElements").previewGestureStart;
+};
+let browser: Browser;
+let studioBundle: string;
+
+beforeAll(async () => {
+ browser = await launchTestChrome();
+ studioBundle = await buildStudioBundle([
+ `export { settleGsapSnapshot } from "./hooks/gsapFrameSnapshot";`,
+ `export { previewGestureStart } from "./player/lib/previewElements";`,
+ ]);
+});
+
+afterAll(() => closeTestChrome(browser));
+
+function previewHtml(): string {
+ const gsap = readFileSync(require.resolve("gsap/dist/gsap.min.js"), "utf8");
+ const runtime = readFileSync(require.resolve("@hyperframes/core/runtime"), "utf8");
+ return `
+
+
+
+
+
Title
+
+
+
+ `;
+}
+
+// fails without the fix: the sealed read asked GSAP for x, GSAP took over the translate and the move saved as gsap.set.
+it.each(MODES)("a move after a GSAP read still saves as a CSS translate (%s)", async (mode) => {
+ const preview = await openPreview(browser, studioBundle, previewHtml(), mode);
+ await preview.seek(1);
+ const start = await preview.page.evaluate(async () => {
+ const studio = (window as unknown as { hfStudio: Reads }).hfStudio;
+ const iframe = document.querySelector("iframe")!;
+ studio.usePlayerStore.setState({ currentTime: 1, isPlaying: false });
+ await studio.settleGsapSnapshot(iframe);
+ const query = await studio.previewRequest(iframe, "query", { selector: "#title" });
+ const handle = (query as { matches: Array<{ handle: string }> } | null)?.matches[0]?.handle;
+ return (await studio.previewGestureStart(iframe, [handle!]))?.elements[0];
+ });
+ expect(start).toMatchObject({ gsap: null });
+ const drawn = await preview.frame.evaluate(
+ () => getComputedStyle(document.getElementById("title")!).translate,
+ );
+ expect(drawn).toBe("0px -200px");
+ await preview.page.close();
+});