Skip to content

fix(studio): a sealed press starts as soon as the frame answers - #8688

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/studio-sealed-press-asks-at-once
Nov 24, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/studio-sealed-press-asks-at-once

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A press on a sealed preview now starts its gesture as soon as the frame answers, about one frame after the press instead of two.

Why

On a sealed preview Studio cannot read the pressed element itself, so a press asks the frame where it is and starts once the answer comes back. A regular preview reads the element directly and starts in the same event.

The press only asked on its first animation frame. When the answer arrived, the press noticed it only on the frame after that. With no save pending, that cost about 32 ms per press on the edit-accuracy bench (old Mac, seqheldtwice-tlhold-px-r0-root-z100): ask at +12-16 ms, all three answers 2-3 ms later, start at +32 ms.

Related work

Refs #7846 (Studio's preview sealed by default): one of the places a sealed preview must behave as a regular one.

How

components/editor/previewGestureStarts.ts, the sealed path only:

  • A press on a sealed frame takes its first look in the press event itself, so the ask goes out at once.
  • When the frame's answer arrives, the press looks again right away instead of on the next animation frame.

A regular preview's waiting press still steps on animation frames: it counts shown frames to decide when to start. The waiting outline after the replay is unchanged. It stays until the frame has drawn the replayed drag, which a test already pins: without it the layer showed at the drag's start for a frame.

Also in this PR: the test owed from #8668, which checks that the keyframe reader waits for the sealed frame's values at the playhead.

Test plan

  • fails without the fix: on an opaque frame asks at the press and starts once the frame answers, with no animation frame in src/components/editor/previewOverlayRects.test.ts failed on main with expected "vi.fn()" to be called once, but got 0 times. With animation frames stubbed out, the press never started.
  • a commit's read waits for the frame's values at the playhead (sealed) in src/hooks/gsapSealedReads.browser.test.ts (real Chrome, both modes). It passes at main, where fix(studio): sealed keyframe edits save the same values as a regular preview #8668 added the wait. With that wait removed on the devbox, the sealed case alone fails (1 failed, 3 passed).
  • On the devbox: both named files 3 runs each, green. The 9 Studio test files that cover the changed file, green. tsc, Fallow and the pre-push hooks clean.
  • Real app: Studio built with the sealed preview on, edit-accuracy bench on the old Mac, with a probe that logs press-to-start for each press (not in this PR). 3 runs per side, load 7-7.6:
press main this branch
no save pending 32, 32 ms 18, 19, 19 ms
right after a save (waits for the save, as a regular preview does) 1615, 734, 1565 ms 1607, 723, 1538 ms

The remaining ~18 ms is the frame's first answer: asked during the press, it takes one frame. Getting to 0 would mean reading the element before the press.

No visible change

This is a timing change on the sealed path: the gesture starts one frame sooner. Nothing is drawn differently, so there is no capture to compare.

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 49 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 3998342.

  • Red-first holds. With main's previewGestureStarts.ts put back, on an opaque frame asks at the press and starts once the frame answers, with no animation frame fails with expected "vi.fn()" to be called once, but got 0 times. At head it passes, along with the rest of previewOverlayRects.test.ts (29/29).
  • The settle-wait test from #8668 behaves as the body says. gsapSealedReads.browser.test.ts passes 4/4 at head in real Chrome. With await settleGsapSnapshot(iframe) taken out of readAllAnimatedProperties, only the sealed case fails (expected {} to deeply equal { rotation: 10 }, 1 failed, 3 passed).
  • An answer from an earlier frame can't start the press. I wrote a scratch test that held the frame's answer and released it on cue:
    • Answer lands after a preview change has begun, then a new iframe replaces the old one: no start while the change runs. The old answer is dropped because askedOf !== frame. The press asks the new frame and starts exactly once, only after that frame answers.
    • Press ended before the answer lands: poll sees press.ended and nothing starts.
    • The early poll() in the press event can't start the gesture by itself. The first channelStep always clears overChannel and returns "wait", so the start always comes from the answer's callback or a later frame.
  • The waits after a save are the same as on main. An ask goes out only from channelStep, after both the queued-press check and the isPreviewChanging() check, and both checks come before it in the same order as on main. The only differences are when the first look happens (in the press event instead of on the next animation frame) and that the answer triggers a look right away. A press behind a save still waits on animation frames until the change ends. The non-sealed path still starts through requestAnimationFrame (pollFirst), so the shown-frame counting there is untouched. pollNow cancels the pending animation frame before it polls, so a press never has two loops running.
  • The 18 Studio unit test files that cover the gesture code pass (226 tests), and tsc --noEmit is clean.

Nit (not from this PR, same on main): if a preview change runs on the same iframe element between the ask and the answer, the press does not ask again once the change ends. It starts from the answer it got before the change, because askedOf === frame. My scratch test shows this at head and on main alike. The window is the 2-18 ms the answer takes, and this PR doesn't widen it. A swapped iframe is handled correctly, as shown above. A possible follow-up is to clear askedOf when a change starts while an ask is out.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit b9dddf3 Nov 24, 2026
79 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-sealed-press-asks-at-once branch November 24, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants