Skip to content

fix(studio): a sealed resize stops asking the frame for an uncropped layer's size every step - #8895

Open
miguel-heygen wants to merge 1 commit into
mainfrom
fix/sealed-resize-crop-read
Open

miguel-heygen wants to merge 1 commit into
mainfrom
fix/sealed-resize-crop-read

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

During a resize in a sealed preview, the crop handles no longer ask the frame for the selected layer's size on every step when the layer has no crop. They read it once when the resize ends.

Why

The crop handles re-read a sealed layer's size from the frame whenever its shown size changes, so its crop insets draw at the layer's own scale. A resize changes the shown size on every pointer step, so every step sent a full gesture-start read to the frame, and each answer re-rendered the crop handles. For a layer with no crop the handles draw the same at any measured size, so those reads did nothing.

Requests Studio sent the frame per resize drag (edit accuracy bench, 8 resize cases, the same change on an earlier main):

sealed before sealed after unsealed
request/reply round trips 122 102 50
gesture-start reads 21 1 (the press) 0
empty scheduler posts 82 62 62

Accuracy was unchanged (8/8 tracking, teleport, drop and reload).

Related work

None open on the crop handles.

How

readStandInStart skips the read while the layer has a live Studio gesture (isStudioManualEditGestureActive) and no crop, and waits for that gesture to end (afterStudioManualEditGestures, the same helper undo uses to hold a repaint) to read once. A layer with crop insets or rounded corners keeps reading on every step, because its insets do scale with the measured size. An uncropped layer reads as zero insets rather than no crop, so "cropped" means any inset or radius above zero. If the crop handles close during the resize, the wait is dropped.

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

packages/studio/src/components/editor/DomEditCropHandles.sealed.test.ts:

  • fails without the fix: "sends a sealed uncropped card no size read while a resize is live, and one when it ends" (4 reads over 3 resize steps, where 1 is right; it also fails when zero insets count as a crop).
  • fails without the fix: "sends no size read when a resize ends after the sealed card's crop handles closed".
  • "keeps reading a sealed cropped card's size while a resize is live, so its insets draw at its own scale" passes before and after, and fails if the skip ignores the crop.

The two crop handle test files pass 3 runs in a row (31 tests). Studio unit suite at this head: 844 files, 9483 tests passed (1 skipped).

@miguel-heygen

miguel-heygen commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

The same sealed resize (edit accuracy bench, resize-size-px-r0-root-z100-mid), captured halfway through the drag. The crop handles sit in the same place on main and on this branch: their boxes were identical at mid-drag, the last step, release and commit. Studio sent the frame 140 requests during this drag on main and 114 on this branch.

Before

Sealed resize mid-drag on main

After

Sealed resize mid-drag on this branch

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 72 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 a7cce2f. Read only (full readStandInStart, useStandInStart and manualEditGesture.ts); I did not run the tests.

Approve.

Need: yes, one frame read per pointer step for a layer whose handles cannot change · Size: small (15 source lines, 3 tests) · Reuse: isStudioManualEditGestureActive and afterStudioManualEditGestures, no new wait mechanism · Simpler: no · Structure: fine
Risk: low. The skip needs both a live gesture on this element and zero insets and radius, so a cropped layer keeps today's path. The crop press does its own read, so a stale start during the resize is never used for a drag.

Checked:

  • held is set once (??=), cleared before the deferred read, and stopped on unmount, so there is one read at the end and none after the handles close. Both are pinned by tests.
  • Zero insets count as uncropped (hasCropInsets or radius > 0), and the cropped guard test fails if the skip ignores the crop.
  • Body names the tests on "fails without the fix:" lines.

Non-blocking:

  • The wait ends when the last gesture in the document ends, not this element's. Fine today; worth a word in the comment if two elements can ever be in a gesture at once.
  • If the selection changes while a read is held, the new element gets its normal read and then one more when the old gesture ends. Harmless, one extra round trip.

— Rames

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

On the two review notes, at a7cce2fe:

  • The wait is document-wide. The skip is per element: a read is held only while the selected stand-in itself has a live gesture (isStudioManualEditGestureActive(el)). The deferred read then runs once no gesture is live in that stand-in's document (afterStudioManualEditGestures, the same helper undo uses), so a second gesture still live on another stand-in delays this one read until it ends too. It never skips the read and never reads during the resize, so the worst case is one read arriving later. A per-element ending would need a new per-element event from manualEditGesture, which I'd rather not add for that.
  • A selection change while waiting costs one extra read. Correct: the new selection reads on its own when it is not under a gesture, and the held wait reads again when the gesture ends. That read lands on whatever is selected then, and the token check in readStandInStart keeps it from applying to a selection it was not taken for, so the drawn result is unchanged. Dropping the wait on a selection change would save that one read per such change. I'm leaving it as is unless you'd like it in this PR.

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.

2 participants