From 39dc1e232d242cdecf9ad782483587b288cc1392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 15 Nov 2026 17:13:42 +0000 Subject: [PATCH] fix(studio): GSAP keyframe and 3D previews stop throwing on a sealed preview (#7833) --- .../components/editor/gsapLivePreview.test.ts | 19 +++++++++++++++++++ .../src/components/editor/gsapLivePreview.ts | 2 ++ .../studio/src/hooks/gsapParsedTween.test.ts | 19 +++++++++++++++++++ packages/studio/src/hooks/gsapParsedTween.ts | 4 +++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/studio/src/components/editor/gsapLivePreview.test.ts b/packages/studio/src/components/editor/gsapLivePreview.test.ts index fef0fe4587..b2ed6cb6cd 100644 --- a/packages/studio/src/components/editor/gsapLivePreview.test.ts +++ b/packages/studio/src/components/editor/gsapLivePreview.test.ts @@ -106,3 +106,22 @@ it.each([ expect(props).toEqual(read); }, ); + +/** A preview on an opaque origin: every read of its window but postMessage throws, as a browser's does. */ +function sealedPreview(): HTMLIFrameElement { + const iframe = document.createElement("iframe"); + const win = new Proxy({} as Record, { + get: (_target, key) => { + if (key === "postMessage") return () => undefined; + throw new DOMException(`blocked read of ${String(key)}`, "SecurityError"); + }, + }); + Object.defineProperty(iframe, "contentWindow", { value: win }); + Object.defineProperty(iframe, "contentDocument", { value: null }); + return iframe; +} + +it("draws nothing on a sealed preview, whose window refuses the read", () => { + const preview = createGsapLivePreview({ current: sealedPreview() }); + expect(() => preview({ id: "card" } as DomEditSelection, { x: 10 })).not.toThrow(); +}); diff --git a/packages/studio/src/components/editor/gsapLivePreview.ts b/packages/studio/src/components/editor/gsapLivePreview.ts index 4f331a3f43..8cd96da372 100644 --- a/packages/studio/src/components/editor/gsapLivePreview.ts +++ b/packages/studio/src/components/editor/gsapLivePreview.ts @@ -1,5 +1,6 @@ import type { DomEditSelection } from "./domEditingTypes"; import { findPreviewNode } from "./domEditingElement"; +import { previewFrameOpaque } from "../../player/lib/previewChannel"; /** * Build the "live preview" callback the 3D-transform sub-view fires while a @@ -12,6 +13,7 @@ import { findPreviewNode } from "./domEditingElement"; export function createGsapLivePreview(iframeRef: { readonly current: HTMLIFrameElement | null }) { return (el: DomEditSelection, props: Record) => { const iframe = iframeRef.current; + if (!iframe || previewFrameOpaque(iframe)) return; const win = iframe?.contentWindow as | { gsap?: { set: (t: Element, v: Record) => void } } | null diff --git a/packages/studio/src/hooks/gsapParsedTween.test.ts b/packages/studio/src/hooks/gsapParsedTween.test.ts index c57393ca79..18aa108092 100644 --- a/packages/studio/src/hooks/gsapParsedTween.test.ts +++ b/packages/studio/src/hooks/gsapParsedTween.test.ts @@ -60,3 +60,22 @@ describe("findParsedTween", () => { timeline.kill(); }); }); + +/** A preview on an opaque origin: every read of its window but postMessage throws, as a browser's does. */ +function sealedPreview(): HTMLIFrameElement { + const iframe = document.createElement("iframe"); + const win = new Proxy({} as Record, { + get: (_target, key) => { + if (key === "postMessage") return () => undefined; + throw new DOMException(`blocked read of ${String(key)}`, "SecurityError"); + }, + }); + Object.defineProperty(iframe, "contentWindow", { value: win }); + Object.defineProperty(iframe, "contentDocument", { value: null }); + return iframe; +} + +it("finds no tween in a sealed preview, whose window refuses the read", () => { + const edit = tween({ method: "to", properties: { x: 300 }, resolvedStart: 0, duration: 2 }); + expect(findParsedTween(sealedPreview(), document.createElement("div"), edit)).toBeNull(); +}); diff --git a/packages/studio/src/hooks/gsapParsedTween.ts b/packages/studio/src/hooks/gsapParsedTween.ts index beedf8fecb..aca47fc2cc 100644 --- a/packages/studio/src/hooks/gsapParsedTween.ts +++ b/packages/studio/src/hooks/gsapParsedTween.ts @@ -2,6 +2,7 @@ import type { GsapAnimation } from "@hyperframes/core/gsap-parser"; import { elementTargets } from "../utils/elementGsap"; import { resolveTweenStart } from "../utils/globalTimeCompiler"; import { KEYFRAME_PCT_MATCH } from "./gsapShared"; +import { previewFrameOpaque } from "../player/lib/previewChannel"; import type { ImplicitEndValue } from "./gsapValueAtPlayhead"; import type { ReadTween } from "./gsapRuntimeKeyframes"; @@ -81,7 +82,8 @@ export function findParsedTween( element: Element, anim: GsapAnimation, ): ParsedTween | null { - const win = iframe?.contentWindow as GsapWindow | null; + if (!iframe || previewFrameOpaque(iframe)) return null; + const win = iframe.contentWindow as GsapWindow | null; const start = resolveTweenStart(anim); if (!win?.__timelines || start == null) return null; const steps = anim.keyframes?.keyframes.map((kf) => kf.properties) ?? [anim.properties];