diff --git a/packages/studio/src/hooks/gsapResizeDropPoint.test.ts b/packages/studio/src/hooks/gsapResizeDropPoint.test.ts index cb28734149..a831424e07 100644 --- a/packages/studio/src/hooks/gsapResizeDropPoint.test.ts +++ b/packages/studio/src/hooks/gsapResizeDropPoint.test.ts @@ -440,9 +440,8 @@ it("lands on the drop point when undo paints the box back while its animations l expect(settled.w).toBeCloseTo(dropPoint.w, 0); }); -// fails without the fix: a sealed scale drop kept the dropped size on Studio's stand-in, so the next resize of the -// layer started from that size on top of the saved scale and jumped, saving the jump. -it("lands on the drop point in a sealed preview, measured by the frame, and leaves no box size behind", async () => { +/** A sealed scale resize dropped at 900x360, with the frame measuring the drop; resolves once it is committed. */ +async function sealedScaleDrop(beforeCommit: (frameElement: HTMLElement) => void = () => {}) { const box = { w: 630, h: 252 }; const base = { x: 489, y: 195 }; const drop = { w: 900, h: 360, x: 300, y: 100 }; @@ -494,6 +493,7 @@ it("lands on the drop point in a sealed preview, measured by the frame, and leav const animations = [scaleTween(false), positionAnimation("static-set", base)!]; const commitMutation = vi.fn(); + beforeCommit(el); const outcome = await tryGsapResizeIntercept( selection, { width: drop.w, height: drop.h }, @@ -513,6 +513,13 @@ it("lands on the drop point in a sealed preview, measured by the frame, and leav }, ); + return { outcome, commitMutation, box, el, dropPoint, standIn: selection.element }; +} + +// fails without the fix: a sealed scale drop kept the dropped size on Studio's stand-in, so the next resize of the +// layer started from that size on top of the saved scale and jumped, saving the jump. +it("lands on the drop point in a sealed preview, measured by the frame, and leaves no box size behind", async () => { + const { outcome, commitMutation, box, el, dropPoint, standIn } = await sealedScaleDrop(); expect(outcome).toMatchObject({ status: "persisted", ownsDragOffset: true }); const written = persistedPositions(commitMutation.mock.calls).at(-1); const scale = persistedScale(commitMutation.mock.calls)!; @@ -521,5 +528,12 @@ it("lands on the drop point in a sealed preview, measured by the frame, and leav expect(shown.x).toBeCloseTo(dropPoint.x, 0); expect(shown.y).toBeCloseTo(dropPoint.y, 0); } - expect(readStudioBoxSize(selection.element)).toEqual({ width: 0, height: 0 }); + expect(readStudioBoxSize(standIn)).toEqual({ width: 0, height: 0 }); +}); + +// fails without the fix: when the frame could not measure the drop (its element gone, as mid-reload), the early return +// cleared the box size only on a scriptable preview's element, so the sealed stand-in kept the dropped size. +it("leaves no box size on the sealed stand-in when the frame cannot measure the drop", async () => { + const { standIn } = await sealedScaleDrop((frameElement) => frameElement.remove()); + expect(readStudioBoxSize(standIn)).toEqual({ width: 0, height: 0 }); }); diff --git a/packages/studio/src/hooks/gsapResizeIntercept.ts b/packages/studio/src/hooks/gsapResizeIntercept.ts index 14b84913eb..fe74a1ffd1 100644 --- a/packages/studio/src/hooks/gsapResizeIntercept.ts +++ b/packages/studio/src/hooks/gsapResizeIntercept.ts @@ -413,7 +413,7 @@ export async function tryGsapResizeIntercept( if (!scaleDraftEl && !frame) return false; const draftEl = scaleDraftEl; if (!scaleDraftDropPoint || !selector) { - if (draftEl) draw(() => clearStudioBoxSize(draftEl)); + draw(() => clearStudioBoxSize(draftEl ?? selection.element)); return false; } const dropPoint = scaleDraftDropPoint;