Skip to content

fix(studio): a sealed press held across a frame swap starts on the frame shown - #8492

Merged
miguel-heygen merged 6 commits into
mainfrom
fix/sealed-held-press-reads-shown-frame
Nov 22, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
fix/sealed-held-press-reads-shown-frame

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

A press made while a sealed preview is changing (a reload, a seek, a save) now starts on the frame that's shown once the change ends. Before, if the change swapped frames, the drag was dropped silently.

Why

On a sealed preview, a press made during a change waits for it to end, then asks the frame over its channel where the pressed element is. It asked the frame that was shown at the press. When the change swapped in a new frame, that frame had already been removed, so:

  • no answer came;
  • the channel's 1 s readiness probe gave up;
  • the lookup came back empty, and the press was dropped.

The person's drag did nothing.

The edit-accuracy sequence seqfastkeys-none-px-r0-root-z100 shows it on every run, sealed only: drag, add a keyframe, seek, drag, seek, drag. The drag right after the seek was pressed while the seek's change was still going and was dropped. Studio-side logs on the bench showed the frame the press held as disconnected and no longer the shown one when it read. A plain preview starts the same drag on the page shown, as the code's own comment says a press during a reload should.

Once that drag started, a second problem showed up. It drew through Studio's stand-in for the element, and stand-ins belong to the frame they were made for. The stand-in was the one from the frame the press began on, so every draft went to the removed frame:

  • the element on screen didn't follow the pointer;
  • it jumped to the drop spot when the save landed.

The bench first read that as the element snapping back at release. A log on every draft message showed all of that drag's drafts going to an iframe no longer in the page.

Related work

Refs #7846 (Studio's preview sealed by default): its edit-accuracy gate flags this sequence.

How

  • previewGestureStarts.ts: once the change ends, a held press reads over the frame shown then. If the frame changes again before the answer arrives, it asks once more (at most two asks). If the frame shown gives no usable answer, the drag starts from the box Studio drew at the press, as a plain preview would. "No usable answer" covers four cases:

    • no reply at all;
    • a malformed reply;
    • a query reply cut short before a match;
    • more elements than the channel describes at once.

    All four used to drop the press. If the frame answers that the element is gone, the press is still dropped, as a plain preview does.

  • previewGestureStartRead.ts:

    • The start read hands the gesture the stand-in for the frame it read over, so the drag draws on the frame shown. The nudge's read gets the same stand-in.
    • askShownGestureStarts keeps "the frame gave no answer" apart from "the frame lacks the element". readShownGestureStarts (the nudge's read) still returns null for both.

Limit: if the change swapped frames and the new frame never answers, Studio has no handle in it, so there's nothing on it to draw through. The drag moves Studio's box, and the element jumps when the save lands. With no swap, a silent frame is the frame shown, and the drag draws through the stand-in it was pressed with.

No visible change

On a sealed preview, a drag pressed during a change now moves the element instead of doing nothing. The interface itself doesn't change.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • previewOverlayRects.test.ts:
    • "reads over the frame shown once the change ends, when the change swapped frames". It also checks that the drag's stand-in is the frame shown's: that part fails against this PR's earlier heads, which kept the pressed frame's stand-in;
    • "starts from the box Studio drew when the frame shown never answers";
    • "starts from the box as it was at the press, though the pointer moved while it waited": fails against the first version of this PR, which read the box after the waiting press had redrawn it.

"asks the frame shown again when a swap comes after its first ask" fails if only one ask is allowed.

The existing "drops the press when the page shown no longer has the element" still passes.

  • Every test under packages/studio/src/components/editor and packages/studio/src/hooks (356 files, 3,990 tests) passes three runs in a row on Linux at this head.
  • On the bench, sealed: the drag after the seek now starts, draws on the frame shown and saves. Every draft of that drag reaches the frame on screen. At release it shows the drawn offset, and the saved position replaces it 54 ms later with no jump. The sequence saves all 4 of its edits, and its tracking check passes. Its teleport and smoothness checks still fail sealed; those are separate work.
  • Pre-commit (format, lint, fallow, typecheck) passes.

…ame shown

A press made while a sealed preview changes waits, then reads where its element is over the frame's channel. It
read over the frame it was pressed on; when the change swapped frames, that frame was gone, no answer came, and the
drag was dropped. It now reads over the frame shown once the change ends, asks again once if that frame changes,
and starts from the box Studio drew when the frame never answers. A frame that answers the element is gone still
drops the press, as a scriptable preview does.
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Quarantined, measured but not gated (0)

Unstable (1)

  • seqrotatenudge-none-center-r0-root-z100: tracking 0.02, pressJump 0, drop 0, reload 3.03, render 0.04, renderKey -, undo false, teleport true / tracking 0.02, pressJump 0, drop 0, reload 0, render 0.05, renderKey -, undo true, teleport true / tracking 0.02, pressJump 0, drop 0, reload 0, render 0.05, renderKey -, undo true, teleport true

@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.

Request changes at 0eff8059. The main fix is sound. The new no-answer fallback starts from a box that has already moved.

Need ✓ · Size ✓ · Reuse ✓ · Simpler ✓ · Structure ✗
Risk: low to medium. It only affects a sealed press held through a frame swap, but the fallback now runs where the press used to be dropped.

What works

  • The start is read from iframeRef.current ?? channel once the swap ends (askShownFrame). The askedOf === frame check discards an answer from the old frame.
  • A second swap asks once more. If no frame answers, the press falls back instead of throwing.
  • A press released while the read is pending is replayed after the start. A press that has ended is skipped in poll. Only animation frames are used, and endWaitingPress cancels them.
  • Red-first: with the two source files from main, exactly the two named tests fail.
  • At head: 106/106 pass across the six test files that import these modules.
  • Mutation: asking the press-time frame turns the swap test red.

Blocker: the fallback box includes the pointer's movement during the wait (previewGestureStarts.ts:357-360)

  • The single-element fallback drawn() reads opts.overlayRectRef.current when the wait ends, not at the press.
  • While the press waits, every pointer move calls drawPressedBox or drawResizedBox. These call opts.setOverlayRect with the shifted or resized box, and setOverlayRect writes overlayRectRef synchronously (useDomEditOverlayRects.ts:83-85).
  • So the gesture starts with originLeft/originTop already moved by the pointer's delta, and useDomEditOverlayGestures.ts:235 (g.originLeft + dx) adds the same delta again.
  • Repro: press a drag during a seek, move 30 px while waiting, and the shown frame never answers. The box starts from left: 31 instead of 1 and draws at about 60 px, and snapping runs against that box. A resize has the same problem with its width and height.
  • The "starts from the box Studio drew" test passes because its mock setOverlayRect never writes the ref and the pointer never moves.
  • Fix: capture the box once at the press, as draw already does, and return that from drawn:
    const pressedRect = opts.overlayRectRef.current;
    Then add a test that moves the pointer during the wait. The group drag's drawn is already correct, because it uses items captured at the press.

P2

  • The second ask has no test. Changing asks >= 2 to asks >= 1 leaves all 46 tests green, because the swap test changes iframeRef before the first ask. A swap after the first ask is already pending would cover it.

  • UNANSWERED covers more than a frame that never answers. It also covers:

    • a selection lookup that finds nothing;
    • a malformed reply;
    • more than MAX_DESCRIBE_HANDLES handles, as in a large group drag.

    Those presses used to be dropped. They now start from the drawn box with no start or snap. That may be intended, but the body's wording doesn't cover it.

— Rames (hf-review)

@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.

Approve at d7e74da8. The blocker from my last review is fixed.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. The change only affects which box and which frame stand-in a press that waited starts from.

  • Blocker resolved: pressedRect is now captured once, at the press. The resize/drag draw and the drawn() fallback both read it, so a press whose frame never answers starts from the box as it was at the press. Before, it read the moved overlayRectRef, which applied the delta twice.
  • Also: askShownGestureStarts now hands the gesture the shown frame's stand-in and handle (standInFor(iframe, onFrame)), so drafts after a frame swap go to the frame shown, not the removed one.

What I checked:

  • Fails without the fix: I put previewGestureStartRead.ts and previewGestureStarts.ts back to 0eff8059. "reads over the frame shown once the change ends, when the change swapped frames" fails on the stand-in check, and "starts from the box as it was at the press…" fails.
  • At the head: 22/22 pass, tsc --noEmit in studio is clean, and merge-tree against main is clean.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit a770f4b Nov 22, 2026
124 of 125 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-held-press-reads-shown-frame branch November 22, 2026 12:53
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