Skip to content

fix(studio): the selection handles move with the box and the layer while dragging - #8909

Open
miguel-heygen wants to merge 3 commits into
mainfrom
fix/sealed-outline-follows-draft
Open

miguel-heygen wants to merge 3 commits into
mainfrom
fix/sealed-outline-follows-draft

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

While you drag a selected layer on the canvas, the selection outline's four resize handles now stay on the layer's corners. Before, they trailed the layer by one frame, and by two on a sealed preview in stock Chrome.

Why

On every pointer move Studio writes the selection box's position straight away, in the move's own task, and the layer moves in that same frame. The resize handles did not take part in that write: their position came only from React's overlayRect state, which commits in a later task, after the frame has already been painted.

Measured on main with stock Chrome, real Studio and OS-level pointer input (XTest), 6 px steps:

  • Write timing: a MutationObserver on Studio's page counted Studio's animation frames between each pointer move and each write. The box was written before the next frame in 33 of 33 moves, in both preview modes; the handles one frame later in 33 of 33, in both modes.
  • On screen: a 60 fps screen capture, with the layer, the outline and the drawn pointer read per displayed frame. The handles trailed the layer by 1 step unsealed and by 1 to 3 steps sealed (sandboxed frame in its own process), varying by session.

Neither mode reads the frame's geometry during a held drag: the per-frame re-measure is paused while a gesture is held, and the drag draws from its own draft.

How

  • DomEditSelectionChrome.tsx: the handles move into a wrapper (DomEditResizeHandles) placed exactly like the box. Each handle is pinned to the wrapper edges of its own corner (left/right, top/bottom), so resizing the wrapper carries the right and bottom handles with it. They stay siblings of the box, so the box's clip path still cannot cut them.
  • drawOutline (domEditOverlayGestures.ts) writes the box and the handles' wrapper together. useDomEditOverlayGestures.ts uses it everywhere it wrote the box before: drag and resize moves, and the tap and release paths. React's later commit writes the same values.
  • No flushSync on a move: forcing React's render into every move would add work to each move under CPU throttling.

Not covered here:

  • The group outline during a group drag is drawn only from React state.
  • The chrome's rotation origin for a rotated element still follows React's commit.
  • On a box under 32 px, the small outward slide of the handles is recomputed only at React's commit during a resize.

Test plan

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

fails without the fix: packages/studio/src/components/editor/selectionHandlesRideTheBox.test.ts "a drag move places the resize handles in the same write as the box" and "a resize move sizes the resize handles in the same write as the box" fail on main (expected [ '', '', '', '' ] to deeply equal [ '50px', '42px', '', '' ]), and again with the handles' wrapper taken out of the move's write.

src/components/editor/: 2215 passed, 0 failed. The two new tests and DomEditSelectionChrome.test.tsx passed three runs in a row. tsc --noEmit in packages/studio is clean. DomEditSelectionChrome complexity is down from 20 cyclomatic / 23 cognitive to 17 / 23.

Screen board on the devbox: stock Chrome, built CLI, the edit-accuracy resize fixture, drags of 40 × 6 px steps, sealed and unsealed sessions interleaved, the preview frame's origin checked each session (null sealed). Below, how many steps the layer and the outline's handles trail the drawn pointer: the most common value over about 39 moving frames per session, 3 sessions per row.

Frame process Preview main: layer / handles this branch: layer / handles
own process (stock) sealed 2 / 4, 3, 4 2 / 2 in every session
own process (stock) unsealed 1–2 / 2–3 same as the layer in every session
shared with Studio (--disable-features=IsolateSandboxedIframes) sealed 3–4 / same as the layer 3 / 2
shared with Studio unsealed 2 / 3 2 / 2

With the sealed frame sharing Studio's process, the handles now lead the layer by one step. The handles are on time there; it is the layer that is late, because a sealed frame in Studio's process applies the drag one frame after Studio paints. That belongs to the separate work on the sealed drag's layer step (the WebKit-class hop), not to the outline. On main the handles' own lag hid it.

Not run: CPU throttling, other browsers.

Before and After captures follow in a comment.

…ile dragging

The resize handles were placed only by React's commit after each move, a frame
after the box border and the element itself, so on screen the outline's corners
trailed the dragged layer. They now sit in a wrapper placed like the box, and
the move writes that wrapper in the same task as the box.
@miguel-heygen

miguel-heygen commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

A rightward drag on a sealed preview (stock Chrome, the sandboxed frame in its own process), 6 px steps, the same displayed frame mid-drag in both runs, enlarged 3x from a 60 fps screen capture.

Before

On main: the box border hugs the layer, but the four resize handles trail it to the left.

before: the resize handles trail the dragged layer

After

On 425990ee: the handles sit on the layer's corners.

after: the resize handles sit on the dragged layer's corners

…test's options current

drawOutline's name says what its two comment lines did. The raw pointer drag test
from main builds the gesture options by hand and now passes the handles' ref too.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Rerun of the board's shared-process rows on 069ff337, which has main with #8899 merged in. The description's shared-process rows predate #8899. Same rig: stock Chrome with --disable-features=IsolateSandboxedIframes, 3 sealed and 3 unsealed sessions interleaved, the preview frame's origin null in every sealed session. Below, how many steps the layer and the handles trail the drawn pointer: the most common value over about 39 moving frames per session.

Preview layer / handles
sealed 2 / 2, 2 / 2, 2 / 2
unsealed 1 / 1, 2 / 2, 2 / 2

With #8899 the sealed layer no longer comes a step late in this mode, so the handles no longer lead it: the "leads by one step" note in the description no longer applies on this head.

@github-actions

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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.

1 participant