Skip to content

fix(studio): a second sealed resize of a scaled layer no longer jumps and saves the jump - #8565

Merged
miguel-heygen merged 11 commits into
mainfrom
fix/sealed-second-scale-resize
Nov 23, 2026
Merged

miguel-heygen merged 11 commits into
mainfrom
fix/sealed-second-scale-resize

Conversation

@miguel-heygen

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

Copy link
Copy Markdown
Collaborator

What

In a sealed preview, a second resize of a layer that has its own scale now starts from the size the first resize saved. Before, it started from the first drop's size on top of the saved scale: the layer jumped as the drag began, and the jump was saved. An unsealed preview was never affected.

Why

Three things left state behind after the first sealed resize of a scaled layer, and the second resize built on each:

  1. The dropped size stayed on Studio's stand-in. Studio writes the dropped size onto the layer's element at release; on the scale route the saved scale replaces it, so the drop has to clear it. Unsealed, the clear ran inside the correction that measures the frame's own element (correctOnElement); a sealed drop measures over the frame's port instead (correctOnFrame) and never reached it. The next gesture read that size as its start (domEditOverlayStartGesture.ts, readStudioBoxSize).
  2. Studio's copy of the frame's GSAP values went stale. A sealed frame's values are read over its port and held (gsapFrameSnapshot.ts), and read again only after a seek, a reload or an undo. A save reruns the frame's script in place at the same playhead, so the second resize read the scale from before the first save (1.125 instead of 1.542) and saved 1.43 where unsealed saves 1.96.
  3. The first gesture's offset stayed on the stand-in. Ending a drag clears Studio's offset when GSAP owns the layer's position (manualOffsetDrag.ts, endManualOffsetDragMembers), but it asked the element's own page for GSAP, which a sealed stand-in doesn't have. The second gesture counted from the leftover offset, and the file saved x 84.392 where unsealed saves 39.706.

Related work

Found while checking sealed resize parity; no bench case did two resizes in a row before this one.

How

  • packages/studio/src/hooks/gsapResizeIntercept.ts: the scale finalize clears the box size once, for both routes, on the element the next resize reads its size from: the frame's own element unsealed, Studio's stand-in sealed. packages/studio/src/hooks/scaleDropPoint.ts: correctOnElement no longer clears it, so there is one clear.
  • packages/studio/src/hooks/gsapFrameSnapshot.ts: rereadGsapSnapshot drops the held values and reads the frame again; the undo handler uses it, and packages/studio/src/utils/gsapSoftReload.ts calls it when a sealed rerun lands.
  • packages/studio/src/components/editor/manualOffsetDrag.ts: whether GSAP owns the position is decided once at the press, from the same read as plainTranslate (the frame's gesture start, sealed), and the drag's end uses it, so a sealed drag runs the same clear as an unsealed one.
  • Bench: seqscaletwice, two resizes in a row on a GSAP-scaled box, root and nested, with its timings and the grid's counts.

Test plan

  • 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

fails without the fix:

  • packages/studio/src/hooks/gsapResizeDropPoint.test.ts, "lands on the drop point in a sealed preview, measured by the frame, and leaves no box size behind": on main the stand-in keeps the dropped 900 x 360 px size after the save.
  • packages/studio/src/utils/gsapSoftReload.sealed.test.ts, "reads the frame's GSAP values again once a saved script reruns in place": without the re-read Studio still reads scaleX 1.125 after the frame reran at 1.542. It also checks the re-read goes once per landed rerun and not after a refused one.
  • packages/studio/src/components/editor/gsapMoveSealedPreview.test.ts, "leaves no Studio offset on the stand-in once a sealed drag ends on GSAP's route": without the fix the stand-in keeps --hf-studio-offset-x: 20px.

Two existing tests list the requests Studio sends the frame: gsapUndoRestore.sealed.test.ts and useGsapScriptCommits.sealed.test.ts. A landed rerun now also sends a gsap-snapshot read, so both leave that one kind out of their lists; every other request they checked is still checked, in the same order.

With the fix, on a Linux machine: the 18 test files that build or end an offset drag or soft-reload a sealed frame, plus gsapResizeDropPoint.test.ts, pass three runs in a row (373 tests), and the bench's own tests pass three runs in a row (126). The push gate's named and covering files (101), Studio tsc, Fallow and pre-push are clean.

Bench

Edit-accuracy bench on a Linux machine, seqscaletwice root and nested, two runs per mode, the same bench throughout, this branch with main merged in. Worst case, in px:

sealed, main sealed, this change unsealed, main unsealed, this change
drop 158.12 0.19 0.19 0.19
reload 158.12 0.06 0.06 0.06
teleport 158 0.24 0.18 0.18
tracking 158.12 0.26 0.06 0.06

The saved files after the second resize, both runs the same:

sealed, this change unsealed
root: 50% scale 1.96 / 1.956 1.96 / 1.956
root: position 39.706, 30.248 39.706, 30.248
nested: 50% scale 1.96 / 1.956 1.96 / 1.956
nested: position 39.708, 30.249 39.707, 30.249

On main sealed saved x 84.392, y 59.594; with the size fix alone, scale 1.43. Before main was merged in, the sealed position was 0.07 px off unsealed's: the sealed drag's corners on a layer with its own scale, which #8562 fixed on main.

No visible change

Sealed previews are off by default, so nothing changes for anyone yet. With them on, a scaled layer resized twice keeps the size it was given.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Traced the three causes at 679abcc: the box-size clear now runs once in finalizeScaleResizeCommit after the commit persists, on draftEl ?? selection.element (correctOnElement has no other caller); rereadGsapSnapshot drops held values and re-reads after a sealed rerun lands and on undo, and the ordered port keeps the read after the write; gsapOwnsPosition is decided at the press and falls back to getOffsetDragGsap without a frame start, so unsealed is unchanged. Fix lines name one test per cause, and the bench shows sealed matching unsealed (158 px to under 0.3 px). Approving.

Small follow-up: the early return in finalize (!scaleDraftDropPoint || !selector) clears only if (draftEl), so a sealed resize with no drop point can still leave the dropped size on the stand-in; use draftEl ?? selection.element there too. Merge this first, then restack #8587/#8598.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 457cc56 Nov 23, 2026
84 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-second-scale-resize branch November 23, 2026 20:18
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