diff --git a/packages/core/src/runtime/editing/gsapSnapshot.test.ts b/packages/core/src/runtime/editing/gsapSnapshot.test.ts
index ccf592c37b..a3c9181d55 100644
--- a/packages/core/src/runtime/editing/gsapSnapshot.test.ts
+++ b/packages/core/src/runtime/editing/gsapSnapshot.test.ts
@@ -135,6 +135,23 @@ describe("gsapSnapshot", () => {
// fails without the fix: GSAP's own state on a keyframes tween's vars tripped the nesting bound, so a sealed preview
// read no GSAP values and Add keyframe at playhead added nothing.
+ it("lists the tweens only GSAP's global timeline runs, once, beside the registered ones", async () => {
+ document.body.innerHTML = `
`;
+ realGsap.globalTimeline.clear();
+ const tl = realGsap.timeline({ paused: true });
+ tl.to("#a", { x: 100, duration: 1 }, 0);
+ realGsap.to("#b", { opacity: 0.5, duration: 1, paused: true });
+ Object.assign(window, { gsap: realGsap, __timelines: { main: tl } });
+
+ const snapshot = await gsapSnapshot();
+ realGsap.globalTimeline.clear();
+
+ const handle = (id: string) => handleFor(document.getElementById(id)!);
+ expect(snapshot.timelines[0]!.tweens.map((tween) => tween.targets)).toEqual([[handle("a")]]);
+ expect(snapshot.globalTweens.map((tween) => tween.targets)).toEqual([[handle("b")]]);
+ expect(snapshot.globalTweens[0]!.vars).toMatchObject({ opacity: 0.5 });
+ });
+
it("reads a real GSAP keyframes tween", async () => {
document.body.innerHTML = ``;
const tl = realGsap.timeline({ paused: true });
diff --git a/packages/core/src/runtime/editing/gsapSnapshot.ts b/packages/core/src/runtime/editing/gsapSnapshot.ts
index f9f6b7f805..eb91901e43 100644
--- a/packages/core/src/runtime/editing/gsapSnapshot.ts
+++ b/packages/core/src/runtime/editing/gsapSnapshot.ts
@@ -55,6 +55,7 @@ export interface GsapSnapshot {
time: number | null;
defaultEase: string | null;
timelines: GsapSnapshotTimeline[];
+ globalTweens: GsapSnapshotTween[];
targets: GsapSnapshotTarget[];
}
@@ -78,6 +79,9 @@ interface LivePropTween {
interface LiveGsap {
getProperty?: (target: Element, prop: string) => unknown;
defaults?: () => { ease?: unknown };
+ globalTimeline?: {
+ getChildren?: (nested: boolean, tweens: boolean, timelines: boolean) => LiveTween[];
+ };
}
interface LiveTimeline {
getChildren?: (nested: boolean) => LiveTween[];
@@ -125,9 +129,11 @@ export async function gsapSnapshot(): Promise {
const gsap = frame.gsap;
const reader = new SnapshotReader();
const timelines: GsapSnapshotTimeline[] = [];
+ const held = new Set();
for (const [id, live] of Object.entries(frame.__timelines ?? {})) {
if (typeof live?.getChildren !== "function") continue;
const tweens = live.getChildren(true).filter((child) => typeof child.targets === "function");
+ for (const tween of tweens) held.add(tween);
if (timelines.length >= MAX_SNAPSHOT_TWEENS) throw new SnapshotBound("timelines");
timelines.push({
id: capped(id),
@@ -136,11 +142,15 @@ export async function gsapSnapshot(): Promise {
tweens: tweens.map((tween) => reader.tween(tween)),
});
}
+ const globalTweens = (gsap?.globalTimeline?.getChildren?.(true, true, false) ?? [])
+ .filter((child) => typeof child.targets === "function" && !held.has(child))
+ .map((tween) => reader.tween(tween));
const time = frame.__player?.getTime?.();
return {
time: typeof time === "number" && Number.isFinite(time) ? time : null,
defaultEase: text(gsap?.defaults?.().ease),
timelines,
+ globalTweens,
targets: reader.targets(gsap),
};
}
diff --git a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
index 4208931b8a..a0c3f8bb43 100644
--- a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
+++ b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
@@ -34,6 +34,7 @@ const snapshot = (over: Record = {}) => ({
time: 0.5,
defaultEase: null,
timelines: [{ id: "main", time: 0.5, defaultEase: null, tweens: [tween] }],
+ globalTweens: [],
targets: [target],
...over,
});
@@ -66,6 +67,8 @@ it.each([
snapshot({ targets: Array.from({ length: 513 }, () => target) }),
],
["a value that is not a number", snapshot({ targets: [{ ...target, values: { x: "7" } }] })],
+ ["no list of global tweens", snapshot({ globalTweens: undefined })],
+ ["a global tween off its shape", snapshot({ globalTweens: [{ ...tween, targets: ["x"] }] })],
[
"a tween start that is not finite",
snapshot({
diff --git a/packages/studio/src/hooks/gsapRoute.sealed.test.tsx b/packages/studio/src/hooks/gsapRoute.sealed.test.tsx
index f86e20a1f2..52c9437093 100644
--- a/packages/studio/src/hooks/gsapRoute.sealed.test.tsx
+++ b/packages/studio/src/hooks/gsapRoute.sealed.test.tsx
@@ -44,6 +44,7 @@ const HANDLE = "0123456789abcdef:1";
const snapshot = (vars: Record | null) => ({
time: 0.5,
defaultEase: null,
+ globalTweens: [],
timelines: [
{
id: "main",
diff --git a/packages/studio/src/hooks/gsapSnapshotGlobalTweens.browser.test.ts b/packages/studio/src/hooks/gsapSnapshotGlobalTweens.browser.test.ts
new file mode 100644
index 0000000000..4072aa4dce
--- /dev/null
+++ b/packages/studio/src/hooks/gsapSnapshotGlobalTweens.browser.test.ts
@@ -0,0 +1,92 @@
+// Real Chrome: a tween only GSAP's global timeline runs reaches a sealed snapshot as a same-origin one.
+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 } 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"];
+let browser: Browser;
+let studioBundle: string;
+
+beforeAll(async () => {
+ browser = await launchTestChrome();
+ studioBundle = await buildStudioBundle([
+ `export { queryPreviewElements } from "./player/lib/previewElements";`,
+ `export { readGsapSnapshot } from "./hooks/gsapSnapshotReply";`,
+ ]);
+});
+
+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 `
+
+
+
+
A
+ B
+
+
+
+ `;
+}
+
+it.each(MODES)(
+ "a tween only GSAP's global timeline runs is in the snapshot once, in a %s preview",
+ async (mode) => {
+ const preview = await openPreview(browser, studioBundle, previewHtml(), mode);
+ try {
+ const read = await preview.page.evaluate(async () => {
+ type Snapshot = {
+ timelines: Array<{ tweens: Array<{ targets: string[] }> }>;
+ globalTweens: Array<{ targets: string[]; vars: Record }>;
+ };
+ type Studio = {
+ previewRequest(
+ iframe: HTMLIFrameElement,
+ kind: string,
+ params: unknown,
+ ): Promise;
+ readGsapSnapshot(value: unknown): Snapshot | null;
+ queryPreviewElements(
+ iframe: HTMLIFrameElement,
+ selector: string,
+ ): Promise<{ matches: Array<{ handle: string }> } | null>;
+ };
+ const studio = (window as unknown as { hfStudio: Studio }).hfStudio;
+ const iframe = document.querySelector("iframe")!;
+ const handle = async (selector: string) =>
+ (await studio.queryPreviewElements(iframe, selector))!.matches[0]!.handle;
+ const snapshot = studio.readGsapSnapshot(
+ await studio.previewRequest(iframe, "gsap-snapshot", {}),
+ )!;
+ const [a, b] = [await handle("#a"), await handle("#b")];
+ return {
+ registered: snapshot.timelines.flatMap((line) => line.tweens.map((t) => t.targets)),
+ global: snapshot.globalTweens.map((t) => t.targets),
+ globalVars: snapshot.globalTweens.map((t) => t.vars),
+ a,
+ b,
+ };
+ });
+ expect(read.registered.filter((targets) => targets.length)).toEqual([[read.a]]);
+ expect(read.global).toEqual([[read.b]]);
+ expect(read.globalVars).toHaveLength(1);
+ expect(read.globalVars[0]).toMatchObject({ color: "rgb(255, 0, 0)" });
+ } finally {
+ await preview.page.close();
+ }
+ },
+);
diff --git a/packages/studio/src/hooks/gsapSnapshotReply.ts b/packages/studio/src/hooks/gsapSnapshotReply.ts
index 0a70930f54..671359caee 100644
--- a/packages/studio/src/hooks/gsapSnapshotReply.ts
+++ b/packages/studio/src/hooks/gsapSnapshotReply.ts
@@ -29,10 +29,12 @@ export function readGsapSnapshot(value: unknown): Snapshot | null {
if (!isFields(value) || !isNumberOrNull(value.time) || !isTextOrNull(value.defaultEase))
return null;
const budget: Budget = { tweens: MAX_SNAPSHOT_TWEENS, fields: MAX_SNAPSHOT_FIELDS };
- const { timelines, targets } = value;
+ const { timelines, globalTweens, targets } = value;
const ok =
isList(timelines, MAX_SNAPSHOT_TWEENS) &&
timelines.every((line) => isTimeline(line, budget)) &&
+ isList(globalTweens, MAX_SNAPSHOT_TWEENS) &&
+ globalTweens.every((tween) => isTween(tween, budget)) &&
isList(targets, MAX_SNAPSHOT_TARGETS) &&
targets.every(isTarget);
return ok ? (value as unknown as Snapshot) : null;
diff --git a/packages/studio/src/utils/gsapSoftReload.sealed.test.ts b/packages/studio/src/utils/gsapSoftReload.sealed.test.ts
index e9320a8360..3cfc954d0d 100644
--- a/packages/studio/src/utils/gsapSoftReload.sealed.test.ts
+++ b/packages/studio/src/utils/gsapSoftReload.sealed.test.ts
@@ -107,6 +107,7 @@ it("reads the frame's GSAP values again once a saved script reruns in place", as
time: 2,
defaultEase: null,
timelines: [{ id: "main", time: 2, defaultEase: null, tweens: [] }],
+ globalTweens: [],
targets: [{ handle: "0123456789abcdef:1", id: "b", className: "", values: { scaleX } }],
});
let scaleX = 1.125;