Skip to content

fix(studio): a sealed drag the preview never answers is refused, not saved wrong - #8720

Merged
miguel-heygen merged 5 commits into
mainfrom
fix/studio-sealed-unanswered-press-refused
Nov 24, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
fix/studio-sealed-unanswered-press-refused

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What

When a sealed preview never answers a press on a layer, Studio now refuses the drag and says why ("The preview didn't answer, so Studio can't move this layer. Try again."), and puts its selection box back on the layer. Before, it started the drag from the box it had drawn and saved a wrong position for a layer whose position GSAP animates.

Why

On a sealed preview Studio can't read the pressed layer itself. A press asks the frame where the layer is, its GSAP position and what it can snap to. If the frame gave no usable answer (no reply in time, a malformed one, or a newly shown frame that never answers), #8492 started the drag anyway from the box Studio drew at the press. That drag had:

  • no snap targets: collectSnapContext reads the frame's document, which a sealed preview doesn't have;
  • no GSAP start: the layer's GSAP x/y read as 0.

On the devbox, with sealed Studio's press reads to the frame dropped, dragging a box held at y: 200 saved its keyframes at y: 125.7 and y: 0. A regular preview saves y: 325.7 and y: 200 for the same drag, so every keyframe was 200 px off. A regular preview never takes this path, since it reads the layer directly.

A nudge on a sealed preview already refuses an unanswered frame with the same message (components/editor/useDomEditNudge.ts:301-303). A drag now does the same.

Related work

Refs #7846 (Studio's preview sealed by default). Partly undoes #8492's fallback for a frame that never answers. A press the frame does answer, including one held across a frame swap, starts as before.

How

components/editor/previewGestureStarts.ts:

  • A press whose frame gave no usable answer no longer starts. The callbacks that handed over Studio's drawn box are gone, and the step is named unanswered instead of drawn.
  • Refusing it draws the waiting box back at the press, then shows the existing toast.

Test plan

  • fails without the fix: refuses a press the frame never answers, saying why: Studio drew a box for it in src/components/editor/previewOverlayRects.test.ts failed on main with expected "vi.fn()" to be called once, but got 0 times: the press started from the drawn box and nothing said why. It replaces the two tests that pinned starting from the drawn box.
  • fails without the fix: puts Studio's box back on the layer when it refuses a press the frame never answers in the same file failed on the first fix commit with the box left 30 px off (left: 31 instead of left: 1).
  • A plain sealed press the frame answers still starts with its snap targets: on an opaque frame waits for what the gesture starts from, read in one request (same file) is unchanged and green.
  • On the devbox: the test file 3 runs, green. The 9 Studio test files that cover the changed file, green. tsc, Fallow and the pre-push hooks clean.
  • Real app: Studio's dev server on the devbox, with a fixture box held at y: 200 and an x keyframed tween. Select the box, drop Studio's query, describe and gesture-start requests to the frame, drag the box 150 px right and 60 px down, wait 8 s, read index.html:
file toast
sealed, main keyframes rewritten at y: 125.7 / y: 0 (200 px off) none
sealed, this branch unchanged shown
regular, this branch (the drag reads the layer directly) keyframes at y: 325.7 / y: 200 none

Before

Sealed preview on main, frame silent: the drag went through and saved the box 200 px off its hold.

Sealed preview on main, frame silent: the drag saved the box 200 px off its hold

After

Sealed preview on this branch, frame silent: the drag is refused with the toast, the box and file are unchanged, and the selection box is back on the layer.

Sealed preview on this branch, frame silent: refused with the toast, box and selection back on the layer

Regular preview, same drag, for comparison:

Regular preview, same drag

  • 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 60 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.

Reviewed at 3aba4d3

APPROVE. I found no blocking issues. A sealed press the frame never answers now ends the same way as a sealed nudge the frame never answers (useDomEditNudge.ts:300-303). Both go through the same askShownGestureStarts read, so they wait the same length of time: a 1 s agent probe, then the 5 s request timeout. Both show the same unansweredMoveReason text through the same onBlockedMoveRef, and neither starts an edit. The drag also draws its box back at the press. A regular (unsealed) preview never reaches this branch: startOnShownPreview starts at once when !channel (line 168), so the nudge is the right thing to match.

Late answers can't write onto anything newer, for three reasons:

  • the port settles a timed-out request once and drops any later reply;
  • askShownFrame ignores an answer for a frame it has stopped asking (askedOf !== frame, line 217);
  • poll returns as soon as the press has ended (line 247).

The removed "start from the drawn box" path was the only path that started a sealed drag with no snap targets and no GSAP start. Dropping it removes the wrong saves the PR describes.

Findings

Nit: a second press queued behind a refused press leaves the box off the layer (previewGestureStarts.ts:272, :354)
The second press takes its origin from overlayRectRef (line 354), and at that point the box is where the first drag drew it. When the first press is refused, the box is drawn back to the layer. When the second is refused, press.draw(0, 0) draws it back to the first drag's end instead.

Probe (scratch test with the file's own helpers, silentFrame()):

  1. Press with the box at left: 1 and draw it to +30.
  2. Release, then press again while the first press still waits.

Both presses are refused, each with the message, and nothing starts. The box ends at {"left":31,...}, not left: 1. This is the off-layer box the second commit fixes, reached through a retry while the first press waits. The file is unchanged and the next answered press starts from the frame's read, so the effect is only visual.

Possible fix: when a refused press still has a press queued behind it, hand that press the refused press's draw-back. For example, unlink could carry the older press's origin forward. Or refuse the queued press too, since it was drawn from a drag that never happened. Fine as a follow-up.

Nit: the draw-back and the message depend on the current selection, not on the press (previewGestureStarts.ts:270-271)
sayWhyNotStarted returns early when opts.selectionRef.current is null. If the selection is cleared while the press waits, nothing is said and the box is left where it was drawn. The probe ended at left: 31 with 0 calls. With no selection the chrome is hidden, so this is invisible today. Still, press.draw?.(0, 0) doesn't need the selection, and for a single press the message could name the pressed target that startGesture already holds. Suggestion: move press.draw?.(0, 0) above the selection guard.

Pre-existing: askShownFrame's void askShownGestureStarts(...).then(...) has no .catch (previewGestureStarts.ts:211)
The nudge's copy has one (useDomEditNudge.ts:295). The read helpers don't reject today, because previewAnswer turns port errors into null, so nothing to do in this PR.

Other probes (all as expected)

  • Group drag, frame silent: the message is shown once and the group boxes go back from left: 31 to left: 1. No start.
  • Teardown mid-press (endWaitingPress() while the read is pending, then wait 2.5 s): 0 messages, 0 starts, no unhandled rejection. The frame loop is cancelled in endWaitingPress, and the late answer hits press.ended.
  • Frame swapped in after the first ask: the existing test asks the frame shown again when a swap comes after its first ask is green, so an answering frame still starts the press.

Test evidence

  • Setup: bun install --frozen-lockfile, then build parsers, lint, core and studio-server.
  • At head: vitest run src/components/editor/previewOverlayRects.test.ts gave 29/29 passed.
  • Red first, with main's previewGestureStarts.ts copied over the PR's copy and the PR's tests kept, 2 failed and 27 passed:
    • refuses a press the frame never answers, saying why: Studio drew a box for it failed with expected "vi.fn()" to be called once, but got 0 times.
    • puts Studio's box back on the layer when it refuses a press the frame never answers failed the same way.
  • On the first fix commit a62e390, the box test fails with left: 31 instead of left: 1, as the body says.
  • After restoring the file, git status --porcelain shows only LFS fixture noise.
  • Related files at head: 12 files, 177/177 passed. They were previewOverlayRects, useDomEditNudge.sealed, gsapMoveSealedPreview, previewGestureStartRead, gestureHoldsPreviewReload, DomEditOverlay, domEditOverlayStartGesture (+blocked), dragUndoPaint, clickAfterPreventedPress, useDomEditNudge and groupDropKeepsSelection.
  • CI: 59 pass, 22 skipping, none failing or pending.

Need: yes, a sealed drag the frame never answered saved keyframes 200 px off · Size: right, -12/+9 in one file plus tests · Reuse: good, the same askShownGestureStarts/UNANSWERED/unansweredMoveReason/onBlockedMoveRef path as the sealed nudge with no second timer, and the draw-back reuses press.draw · Simpler: yes, it removes the drawn callbacks and a step · Structure: fine, startsFrom now starts only on run

Risk: low — it only changes what happens when a sealed frame gives no usable answer, it now refuses instead of saving a wrong position, and an answered press is unchanged.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 2ffa5ae Nov 24, 2026
81 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-sealed-unanswered-press-refused branch November 24, 2026 19:18
@miguel-heygen miguel-heygen mentioned this pull request Nov 24, 2026
3 of 4 tasks
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