Skip to content

Commit 8b80c24

Browse files
fix(studio): a press on an animated layer in a sealed preview starts at once (#9121)
A drawn motion path asks the frame where it starts every frame. That ask counted as a change to the frame, so the read a press starts from was thrown away every frame and each press on an animated layer waited for the frame. On a busy machine the first move showed a step behind the pointer. motion-path-home, assets-unloaded and stage-measure only read the frame; they join the list of read-only requests.
1 parent 78ee605 commit 8b80c24

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/studio/src/components/editor/gestureStartReadAhead.sealed.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures"
1414
import { gestureStartReadAhead, keepGestureStartReadAhead } from "./gestureStartReadAhead";
1515
import { createPreviewGestureStarts } from "./previewGestureStarts";
1616
import { standInFor } from "./previewSelection";
17+
import { sealedMotionPathHome } from "./useMotionPathData";
1718
import { useDomEditOverlayRects } from "./useDomEditOverlayRects";
1819

1920
const frames = vi.hoisted(() => new Set<() => void>());
@@ -131,6 +132,19 @@ const press = () =>
131132
const asked = (kind: string) =>
132133
vi.mocked(previewRequest).mock.calls.filter(([, k]) => k === kind).length;
133134

135+
// fails without the fix: a drawn motion path asks where it starts every frame, and each ask threw away the read
136+
// made before the press, so the press waited on the frame and its first move showed late.
137+
it("starts a press at once while a drawn motion path keeps asking the frame where it starts", async () => {
138+
const { iframe, selection, opts } = await selectBoxOnSealedFrame();
139+
expect(await sealedMotionPathHome(iframe, "#box")).not.toBeNull();
140+
141+
const starts = createPreviewGestureStarts(opts, vi.fn(), vi.fn());
142+
expect(starts.startGesture("drag", press(), { selection })).toBe(true);
143+
144+
expect(opts.gestureRef.current?.selection.handle).toBe(selection.handle);
145+
expect(opts.waitingPressRef.current).toBeNull();
146+
});
147+
134148
// fails without the fix: the press waited on query, describe and gesture-start answers before its gesture started.
135149
it("starts a press on a sealed preview at once from the read made before it, asking the frame nothing", async () => {
136150
const { selection, opts } = await selectBoxOnSealedFrame();

‎packages/studio/src/player/lib/frameFacts.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ it("hears a draft or any other write to the frame, and no read of it", () => {
1616
const changes = heard();
1717
frameRequestSent("query");
1818
frameRequestSent("gesture-start");
19+
frameRequestSent("motion-path-home");
20+
frameRequestSent("stage-measure");
21+
frameRequestSent("assets-unloaded");
1922
frameRequestSent("draft");
2023
frameRequestSent("edit-element");
2124
frameRequestSent("soft-reload");

‎packages/studio/src/player/lib/frameFacts.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const FRAME_READS: ReadonlySet<EditingRequestKind> = new Set<EditingRequestKind>
5151
"gsap-snapshot",
5252
"max-z-index",
5353
"stacking-family",
54+
"motion-path-home",
55+
"stage-measure",
56+
"assets-unloaded",
5457
]);
5558

5659
export function frameRequestSent(kind: EditingRequestKind): void {

0 commit comments

Comments
 (0)