Repository navigation
fix(studio): crop and scale resize work in a sealed preview - #8005
Conversation
Edit accuracy: accurate 271 (base branch 271), smooth 65 of thoseThe gate passes. Quarantined, measured but not gated (0) |
571e1ea to
e3c1a03
Compare
vanceingalls
left a comment
There was a problem hiding this comment.
Changes requested at e3c1a03. The port side is clean: crop-lift is in EDITING_REQUEST_KINDS, PARAM_PARSERS and HANDLERS, the keys are an exact whitelist, lift must be a boolean, handle goes through isHandle, there's no new listener, and nothing beyond computed-styles is exposed. The fails without the fix: tests exist.
Blockers:
- Frame-reported size is persisted unbounded (the #8002 failure again).
gsapResizeIntercept.ts(~L325) now usesgestureStartLayout(handle), frompreviewGestureStartRead.ts, ascssW/cssHfor a sealed preview. Those values come from the frame and are only checked withNumber.isFinite(previewElements.ts:240).started?.width || 200catches 0 but not-5or1e-9, so a reply like that persists a negative or enormousscaleinto the project. Bound the width and height to(0, MAX_DRAFT_PX], and fall back to 200 otherwise. - A crop lift can stay stuck. In
domEditOverlayCrop.ts(liftInFrame), when the lift reply is null (a timeout or a race), the record is deleted even though the frame may have applied the rule. The later restore then finds no record and never un-lifts, so the crop stays hidden in the frame. Thelift:falserequest is also fire-and-forget. Keep the record until the un-lift is confirmed.
Should-fix:
- Stale layouts:
startLayoutsis a module-levelMapkeyed by handle and never evicted, so a stale layout can carry across iframes and reloads. Use aWeakMapkeyed by the stand-in, or clear it on port close. - Unbounded clip-path:
clipPathin the reply andframeClipPathshave no length cap. Truncate toMAX_ELEMENT_VALUEand cap the parsed insets.
|
Thanks, all four fixed in 1. Frame-reported size. Fixed where the reply is accepted. 2. Stuck crop lift. A lift whose reply is lost keeps its record, so deselecting still sends Should-fix 1. Should-fix 2. A |
vanceingalls
left a comment
There was a problem hiding this comment.
Approved at 5110212. Both blockers are fixed.
- Frame-reported size:
isLayoutinpreviewElements.tsbounds the frame's width and height to[0, MAX_DRAFT_PX]at the reply parser.previewGestureStartReadkeeps a start box only when both sides are at least 1 px, and clearsstartLayoutson each measure. A bad reply now falls back to 200 instead of being persisted as a negative or enormous scale. - Stuck crop lift: a lift record is kept until the frame confirms
lifted === false, with up to 3 un-lift tries. A null lift reply no longer deletes the record. After the retries,droppedlets the next crop start a fresh lift, so nothing stays stuck.
The should-fixes are also in: the reply clipPath is capped at MAX_ELEMENT_VALUE, and the parsed insets are bounded by MAX_DRAFT_PX.
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at ca08a97. This is a refactor only: the stylesheet clip under a lift is read in sheetClipUnder. readElementClipPath is unchanged in behaviour (inline first, then the sheet clip while a lift is live and not dropped, otherwise the computed clip).
ca08a97 to
c7e76b7
Compare
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at a4330d8. This is a one-line test fix, with no source change: the crop-lift test helper now answers the lift it just sent.
a4330d8 to
0a6cb2b
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at 0a6cb2b9. This was my first review of this PR, so I reviewed all of it as well as the rebase.
The rebase holds. git range-diff from the last approved head a4330d89 shows commits 3–6 byte-identical. Commits 1–2 differ only in context that main moved underneath them: the watch-geometry kind and the marked-agent import. watch-geometry and crop-lift both appear, in the same order, in EDITING_REQUEST_KINDS, EditingRequests, PARAM_PARSERS and HANDLERS, and in both test lists.
The parser is strict. It requires exactly handle and lift, a valid handle and a real boolean. An extra key, a missing lift, lift:"true", handle:"body", an array or null each get invalid-params.
The frame handler is narrow. It only acts on the element the handle resolves to. It replaces its own earlier rule instead of adding another, and it adds a single clip-path:none!important rule.
Studio treats the reply as untrusted.
- It checks the reply's type, caps
clipPathatMAX_ELEMENT_VALUE, and rejects crop edges aboveMAX_DRAFT_PX. - Un-lifting stops after 3 tries.
isLayoutrequires a finite size within bounds, and a reply must be the same length as its request.
Tests and mutation check. Core editing* passes 237 and the studio suites pass 127. With the crop-lift handler removed, the named "uncropped while selected" test fails.
Nit (non-blocking). At cropLift.ts:12, the selector quoting escapes only " and \. A newline in an id would end the CSS string early. That stays inside the frame's own stylesheet, so it crosses no boundary, but CSS.escape would be tidier here and in Studio's liftSelector.
CI. No failures; some jobs were still running.
— Rames
0a6cb2b to
3cc7499
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Re-stamp at 3cc7499: this is a rebase only, onto main after #8011.
The +/- lines of the patch against its new base are identical to the head I approved at 0a6cb2b. The new head equals merge-tree(origin/main, 0a6cb2b9) with its conflicts resolved. Every conflicted list keeps main's four new entries (audio-meter, document-markup, set-audio-group-attribute, assign-audio-group) followed by this PR's crop-lift:
EDITING_REQUEST_KINDS- the
EditingRequeststypes PARAM_PARSERSHANDLERS- both test expectation arrays
Verified:
- core editing tests: 245 pass.
- studio crop-lift and selection tests: 43 pass.
- CI: 0 failed. Some checks are still pending.
Need from author: nothing.
— Rames
a9fd650 to
bb977ac
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Re-approve at bb977ac4. I ran git range-diff from my last approved head, 3cc74998, to this one, each against its own merge-base with main.
- Commits 1, 4, 5 and 6 are unchanged (
=). - In commits 2 and 3 only the context changed: main's newer
gsap-snapshotandmotion-path-homeentries now sit besidecrop-liftinEDITING_REQUEST_KINDS,EditingRequests,PARAM_PARSERSand the agent'sHANDLERS, and some import lines inpreviewGestureStartRead.test.tsmoved. Every added line in the PR is the same.
So this is a rebase only, as the body says.
— Rames
Verdict: APPROVE. Needs reuse: no. Over-engineered: no.
…t or bad frame replies
… or bad frame replies
bb977ac to
74353bc
Compare
What changed
With the preview sealed (
VITE_STUDIO_OPAQUE_PREVIEW_ENABLED), Studio's selection is a stand-in element with no styles or box of its own. Two edits read the real element and so went wrong:clip-pathfrom the stand-in, which has none, so a cropped element showed no crop and a second drag started from zero. A sealed selection now remembers the frame's inline and computedclip-path(as it already does fortranslate), and the crop reads that.clip-pathso the cropped-away part shows dimmed. In a sealed preview that rule has to live in the frame, so the editing port gets acrop-liftkind (packages/core/src/runtime/editing/cropLift.ts). It adds or removes the same[data-hf-id]/[id]rule Studio writes today, and answers with the element's clip under the lift. The element's ownclip-pathstays the saved record.real / 200. The gesture-start read already measures that box; it is now kept per element and used when the frame element can't be read.With the flag off nothing changes: every new path is taken only for a stand-in.
What I measured
On the devbox, at origin/main with only the new tests applied, all three fail. With the fix: the 21 Studio test files and 4 core test files that import a changed module pass in each of three runs, and
tscpasses for core and studio.fails without the fix: "reads the clip-path the frame renders, as a scriptable frame's does" and "shows the element uncropped in the frame while selected, and crops it again after" in
packages/studio/src/components/editor/previewSelection.test.ts, and "scales from the box its gesture started from, not a 200 px fallback" inpackages/studio/src/components/editor/previewGestureStartRead.test.ts.What I did NOT exercise
Before
main, Studio built withVITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1, headless Chrome at 1600x900, the edit-accuracy fixture with the target cropped byinset(20px 60px 30px 40px), target selected. The preview frame is sealed, so Studio can't read the crop: the target stays cropped and only the resize corners show.After
This branch, same setup. The crop lift runs in the frame: the target shows uncropped, the cut-away area is dimmed, and the four crop edges sit on the crop.