Skip to content

fix(studio): a sealed crop lands where it was dragged - #8279

Merged
miguel-heygen merged 3 commits into
mainfrom
fix/sealed-crop-frame
Nov 20, 2026
Merged

miguel-heygen merged 3 commits into
mainfrom
fix/sealed-crop-frame

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

In a sealed preview (Studio cannot script the frame), a crop now lands where it was dragged:

  • On a layer GSAP turns or scales, the drag maps through the layer's own turn and scale. Before, a crop on a spun layer was saved 25 to 99 px off, and on a scaled one 5 to 20 px off.
  • On release, the crop stays where it was let go. Before, it snapped back to where it was at the press until the save came back, on every crop, whether the layer animates or not.
  • After an undo the frame restores in place, the selection shows the undone crop. Before, it kept showing the crop that was undone.

The second change applies to every sealed style edit, not only crop: an opacity or color edit also shows on the selection at once.

The sealed preview is off by default until the sealed-by-default change (#7846) lands, so nothing changes for anyone before then.

Why

A gesture on a sealed preview edits Studio's stand-in for the element: an element with no layout, no styles of its own, and none of GSAP's transform. Each problem came from reading the stand-in where the frame's own element was needed.

  1. Crop geometry. DomEditCropHandles maps the drag through readElementCropFrame(selection.element). On a stand-in it found no transform and no size, so it fell back to the box's screen bounds: angle 0 and the zoom as the only scale. The drag was never turned into the layer's frame and was divided by the zoom alone, so the error grew with the layer's turn or scale at the playhead.
  2. Release snap. Once the drag ends, the handles draw the element's committed crop. On a stand-in that is its inline clip-path, else the clip the frame reported when the layer was selected. The style commit wrote a live element's style at once, but in a sealed preview it only sent the edit to the frame, so the stand-in kept the old crop until the save's resync.
  3. In-place undo. After a sealed undo restored in place, nothing re-read the selection. The undo path only resynced the automation lanes, and the frame answers after it returns. This is true of any sealed in-place undo, not only crop.

How

  1. Crop geometry, through the gesture-start read every sealed press already makes:
    • Core gesture-start also reports planar, the turn and scale the element paints under (its own transform with its ancestors'), next to the offset size it already sends.
    • Studio's reader bounds it; a value out of range drops only that field.
    • readElementCropFrame takes the frame's turn, scale and size from that read for a stand-in.
    • A crop press on a stand-in reads it once. Moves before the reply keep only the latest pointer, and a release before the reply commits after it. If the frame cannot answer, the press is cancelled rather than drawn with the wrong frame.
  2. Release snap: commitDomStyles also writes a sealed edit's styles on the stand-in and records which. A failed save puts the stand-in's previous inline styles back exactly. Every re-read of the selection (the one place frame values come back fresh) resets those recorded properties to the frame's current inline value, so a copy never outlives a later change in the frame.
  3. In-place undo: a sealed restore the frame applied in place (restore-attributes, or the script re-run) announces it on the iframe. useDomEditPreviewSync, which already re-reads the selection when a preview loads, re-reads it then too. Only the selection reacts.

Readers of a stand-in's inline style, checked before writing to it:

  • the crop read (domEditOverlayCrop.ts readElementClipPath), the reader this is for;
  • the move undo's placement and translate (gestureUndoRevert.ts), which draws a translate relative to the stand-in's own start: commitDomStyles refuses left, top, width and height, and a copied translate equals what the frame holds, so the draft stays right;
  • the resize and rotate look snapshot (gestureUndoRevert.ts readElementLook), which is restored on the stand-in only;
  • the styles copied once when a stand-in is made (previewSelection.ts);
  • the commit's own capture (domStyleCommit.ts).

No frame request is built from a stand-in's inline style.

Test plan

  • editingGestureStart.test.ts: gesture-start reports the transform an element paints under, its own composed with its parent's.
  • DomEditCropHandles.sealed.test.ts: a crop on a sealed card GSAP draws at twice its size, and on one turned a quarter, saves the crop an unsealed crop saves. Both drag and let go before the frame answers.
  • domEditCommits.sealed.test.ts:
    • a sealed style commit shows on the selection before the save lands (crop and opacity);
    • a failed sealed save puts the selection's style back exactly;
    • after a real sealed undo restored in place, the selection shows the undone crop.
  • useDomEditPreviewSync.test.ts: the selection is re-read when a sealed preview restores an undo in place, as when it loads a new page.

fails without the fix:

  • with gesture-start not reporting the transform, the gesture-start test and both crop tests fail; with the crop frame ignoring the read, or a stand-in's press never asking for it, both crop tests fail;
  • with the stand-in never shown the commit, "shows a sealed style commit on the selection at once" fails; with the revert only on a live element, "puts the selection's own style back exactly" fails;
  • with the in-place restore not announced, or the re-read keeping the copied styles, "shows the undone crop on the selection after a sealed undo restores it in place" fails; with the preview sync not listening, "re-resolves the selection when a sealed preview restores an undo in place" fails.

Run on Linux at this head: core editingGestureStart, editingGeometry, editingAgent, editingPort (192 tests) and Studio's touched crop, style commit, preview sync, sealed undo and soft-reload tests (161) pass three runs in a row; core and Studio tsc no errors; format clean; the code audit passes.

Bench

Edit-accuracy bench, every crop case at r0 (60), on the sealed-by-default change at 9028129, before and after this change:

preview drop off teleport failing cases
sealed, before 12 60 60
sealed, after 0 6 36
unsealed, before 0 0 31
unsealed, after 0 0 29

The unsealed failing cases, and most sealed ones after, fail only smooth, which the gate reports and does not count.

Known and next: the six crop cases on a layer GSAP spins still fail teleport and tracking after the release. Their crop is off by 21, 42 and 82 px (growing with the turn) 15 to 25 frames after the pointer comes up, not at it. The saved crop is right (drop 0). The likely cause is the crop drawn while no gesture holds the frame's turn: a stand-in's crop is drawn from its unturned box outside a press. It is the next change.

Sealed undo or redo misses: 4 before, 5 after (one undo). They are 40 px misses on root cases at 50% zoom. In two earlier re-runs of three of these cases without this change, the same 40 px miss moved between cases and between undo and redo, so they read as timing, not this change. This run's five have not been re-run one at a time.

Before

Sealed preview, a layer GSAP spins (40 degrees at the playhead), its right crop edge dragged in. Just after the release the drawn crop is straight and 31 px from where it was let go; the saved crop is 99 px off.

before: just after the release, the crop is drawn straight, 31 px off

before: after the save, the saved crop is 99 px off

After

The same crop: drawn on the turned box and 0 px off just after the release, and saved where it was let go.

after: just after the release, the crop is drawn on the turned box, 0 px off

after: after the save, the saved crop is 0 px off

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 79 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)

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

Verified

  • gesture-start now reports planar, the a-d of readElementTransformSnapshot. That is the same composed transform (the element's own and its ancestors') that Studio's readPlanarTransform reads for a live element. So a stand-in's crop frame gets the turn, scale and layout size the unsealed path already uses, and the edit scale is still applied on top.
  • The press/reply handling: waiting is set before the first await. Moves before the reply keep only the latest pointer, and a release before the reply commits once it arrives. A reply that lands after a cancelled press or a newer press is ignored (settleMeasuredPress), and a null reply cancels the press back to its start insets. A live element resolves undefined and runs exactly as before.
  • commitDomStyles: the capture/revert now runs on the stand-in for a sealed edit, so a failed save puts its previous inline values back. The copied properties are reset to the frame's own inline value on every selection re-read, so they never outlive a later frame change.
  • The undo announce fires only on an applied restore-attributes reply or a soft re-run that did not return cannot-soft-reload. Fallbacks still go through reloadPreview.
  • Tests at this head, after building parsers/lint/core/studio-server: core editingGestureStart.test.ts 14/14. Studio crop handles, crop overlay, sealed commits, preview sync, undo restore, soft reload and preview elements: 210/210, twice.
  • Mutation checks:
    • With readElementCropFrame ignoring the measured start, both new sealed crop tests fail.
    • With the showSavedStylesOnStandIn call removed from the commit, "shows a sealed style commit on the selection at once" and "shows the undone crop on the selection after a sealed undo restores it in place" fail.

Non-blocking

  • The measured start stays in the handles' state after the press until the selection changes. Scrubbing to a frame where a GSAP layer has a different turn therefore draws the idle crop at the press-time angle. Before this change it was drawn at 0°, so this is no worse, and it sits next to the follow-up you already list.
  • isPlanarOrNull bounds the matrix entries with MAX_DRAFT_PX. These are unitless, so a tighter bound would fit better, but it only drops a bad field.

Need to fix: none. Approving once CI is green.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit a755e3f Nov 20, 2026
100 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-crop-frame branch November 20, 2026 08:44
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