From 93622154ef0a0f5256bbd2432f6a92b5999eefea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 17 Nov 2026 20:08:22 +0000 Subject: [PATCH] fix(studio): a click after two quick seeks adds the keyframe in a sealed preview (#8103) * test(studio): a click after two quick seeks reads GSAP values at the playhead * fix(studio): a click after two quick seeks waits for the sealed preview's read at the playhead --- .../src/hooks/gsapFrameSnapshot.test.ts | 22 ++++++++++++++++++- .../studio/src/hooks/gsapFrameSnapshot.ts | 8 +++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts index b490eed105..56087a3b50 100644 --- a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts +++ b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts @@ -16,7 +16,7 @@ vi.mock("../player/lib/previewChannel", () => { }); import { usePlayerStore } from "../player/store/playerStore"; -import { frameDocument, frameTimelines, settleGsapSnapshot } from "./gsapFrameSnapshot"; +import { frameDocument, frameGsap, frameTimelines, settleGsapSnapshot } from "./gsapFrameSnapshot"; const HANDLE = "0123456789abcdef:1"; const tween = { @@ -91,3 +91,23 @@ it("keeps a timeline named __proto__ as a timeline, not the record's prototype", expect(Object.keys(frameTimelines(iframe) ?? {})).toEqual(["__proto__"]); }); + +// fails without the fix: a click waited on the read the first seek started, which holds that seek's time, so right +// after a second seek it found no GSAP values at the playhead and the add did nothing. +it("waits for a read at the playhead when a second seek lands while the first read is out", async () => { + usePlayerStore.setState({ currentTime: 0.5, isPlaying: false }); + let answerFirst = (_reply: unknown) => {}; + request.mockImplementationOnce(() => new Promise((resolve) => (answerFirst = resolve))); + const atOne = { id: "main", time: 1, defaultEase: null, tweens: [tween] }; + request.mockResolvedValueOnce(snapshot({ time: 1, timelines: [atOne] })); + const iframe = document.createElement("iframe"); + + const first = settleGsapSnapshot(iframe); + usePlayerStore.setState({ currentTime: 1 }); + const click = settleGsapSnapshot(iframe); + answerFirst(snapshot()); + await Promise.all([first, click]); + + expect(request).toHaveBeenCalledTimes(2); + expect(frameGsap(iframe)).not.toBeNull(); +}); diff --git a/packages/studio/src/hooks/gsapFrameSnapshot.ts b/packages/studio/src/hooks/gsapFrameSnapshot.ts index 80298db6d2..0f68e29c16 100644 --- a/packages/studio/src/hooks/gsapFrameSnapshot.ts +++ b/packages/studio/src/hooks/gsapFrameSnapshot.ts @@ -78,8 +78,12 @@ function refreshGsapSnapshot(iframe: HTMLIFrameElement): Promise { /** Reads the frame again unless the held read is at the paused playhead, for async callers. */ export async function settleGsapSnapshot(iframe: HTMLIFrameElement | null): Promise { if (!iframe || !previewFrameOpaque(iframe)) return; - const snapshot = held.get(previewEditingClient(iframe)); - if (!snapshot || !fresh(snapshot)) await refreshGsapSnapshot(iframe); + const client = previewEditingClient(iframe); + for (let reads = 0; reads < 2; reads++) { + const snapshot = held.get(client); + if (snapshot && fresh(snapshot)) return; + await refreshGsapSnapshot(iframe); + } } async function read(iframe: HTMLIFrameElement, client: EditingPortClient): Promise {