mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
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
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -78,8 +78,12 @@ function refreshGsapSnapshot(iframe: HTMLIFrameElement): Promise<void> {
|
||||
/** Reads the frame again unless the held read is at the paused playhead, for async callers. */
|
||||
export async function settleGsapSnapshot(iframe: HTMLIFrameElement | null): Promise<void> {
|
||||
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<void> {
|
||||
|
||||
Reference in New Issue
Block a user