Repository navigation
fix(studio): a sealed Layers pick of a cropped layer puts its resize corners on the whole layer - #8468
Conversation
…corners on the whole layer
Edit accuracy: accurate 271 (base branch 271), smooth 71 of thoseThe gate passes. Quarantined, measured but not gated (0) |
vanceingalls
left a comment
There was a problem hiding this comment.
Approved at 6210351, CI green. The crop lift was a plain map read during render, so in a sealed preview, where the frame's measure comes back the same, React skipped the commit and the selection box kept hugging the crop. Now every change to a lift goes through setLift and bumps a version. useCropOverlay subscribes with useSyncExternalStore (subscribeCropLifts and cropLiftsVersion), so the box redraws when a lift starts, lands, is refused or drops, in both kinds of preview. The sealed test checks the hug goes away on lift and comes back on a refusal, and fails without the fix. The unsealed case is pinned too. It doesn't touch DomEditCropHandles.tsx, so it won't collide with #8451.
Nit: dropElementCropLift calls setLift(element, null), which already notifies, and then liftsChanged() again, so subscribers render twice on a drop. It's harmless, but it can lose one call.
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at 5600a71. Since 6210351 the only change is 5600a719, which shortens one test comment to fit the line limit. No code changed.
Correction to my earlier nit: dropElementCropLift notifies once on each path. The lift.rule branch calls setLift(element, null) and returns, and only the frame-unlift branch calls liftsChanged(). I misread the diff fragments. Nothing to change there.
What
In a sealed preview (Studio cannot script the frame), picking a cropped layer in the Layers panel now puts its resize corners on the whole layer, as an unsealed preview does. Before, the corners and the selection outline stayed pulled in to the crop, and on a scaled layer they landed short of even that, until something else made the overlay redraw.
Why
While a cropped layer is selected, Studio lifts its crop so the whole layer shows and the cut-away part can be dimmed. Until the lift, the selection box hugs the crop. The overlay read "is it lifted" from a plain map during render. The lift is made a moment later, by the crop handles. The overlay did render again after that, but nothing React tracks had changed (the measured box was the same), so React skipped committing that render and the box kept its pre-lift hug.
An unsealed preview hid this: its lift changes the element itself, so the overlay's next measure set new state and the box redrew. A sealed frame's measure comes back the same, so the hug stayed for good: at the pick, 2 s later, and after a mouse move.
Related work
Refs #8451 (the same layer's crop insets at its own scale in a sealed preview). That PR changes
DomEditCropHandles.tsx; this one does not touch it.How
domEditOverlayCrop.ts: the crop lift becomes a small store. Every change to a lift goes throughsetLift(or marks it dropped), and each change notifies subscribers.subscribeCropLiftsandcropLiftsVersionexpose it.useCropOverlay.ts: subscribes withuseSyncExternalStore, so the overlay redraws when a lift starts, lands, is refused by the frame, or drops, in both kinds of preview.Before
Sealed, main: a cropped layer scaled by GSAP, clicked at 1 s, Escape, seek to 3.5 s, picked in Layers. The corners sit on the crop, short of the layer.
After
Sealed, this change, same steps: the corners sit on the whole layer. Then unsealed, for reference.
The dashed crop line and the side handles still differ from unsealed in the sealed capture: that is the inset scale #8451 fixes.
Test plan
useCropOverlay.test.ts("a sealed layer picked with no press drops its crop hug once the crop handles lift it, and gets it back when the frame refuses" and "an unsealed layer's crop hug follows its lift and its drop"). Onmainboth fail withexpected 150 to be null: the hug stays after the lift.useCropOverlay.test.ts,domEditOverlayCrop.test.ts,domEditOverlayCropLift.test.ts,domEditOverlayCropFrameLift.test.ts,DomEditCropHandles.test.tsx,DomEditCropHandles.sealed.test.tsandDomEditOverlay.test.ts(83 tests), and studio'stsc --noEmit.Not exercised: macOS and Safari (Chrome on Linux only); a rotated cropped layer picked in Layers.