From 64b94ebf3a5ac4611292e10f6b676a4616e9dfe2 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Thu, 20 Aug 2026 23:38:39 -0700 Subject: [PATCH] fix(studio): resume drag-paused timelines instead of only re-seeking (#1876) Drag start pauses every window.__timelines entry and records the list in data-hf-drag-paused-timelines; resumeGsapTimelines then removed the attribute and only re-seeked the player, never unpausing anything. The main timeline survives (seek-driven every frame) but play-state-driven sub-composition timelines froze permanently after any element drag, and deselecting could not recover them. Now unpauses exactly the recorded ids (never touching timelines the drag did not pause) before the player re-seek. Verified live: after a real drag on an animated element all scene timelines stay unpaused. Co-authored-by: Claude Fable 5 --- .../editor/manualOffsetDrag.test.ts | 49 +++++++++++++++++++ .../src/components/editor/manualOffsetDrag.ts | 14 +++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/studio/src/components/editor/manualOffsetDrag.test.ts b/packages/studio/src/components/editor/manualOffsetDrag.test.ts index 0db15b1149..514e29e592 100644 --- a/packages/studio/src/components/editor/manualOffsetDrag.test.ts +++ b/packages/studio/src/components/editor/manualOffsetDrag.test.ts @@ -2,6 +2,7 @@ import { Window } from "happy-dom"; import { describe, expect, it } from "vitest"; import { applyManualOffsetDragCommit, + resumeGsapTimelines, applyManualOffsetDragDraft, applyManualOffsetDragMatrix, createManualOffsetDragMember, @@ -447,3 +448,51 @@ describe("GSAP-element drag — dot-a flies regressions", () => { expect(element.style.getPropertyValue("transform")).toMatch(/translate\(/); }); }); + +describe("resumeGsapTimelines", () => { + it("unpauses exactly the timelines the drag start paused, then re-seeks the player", () => { + const window = new Window(); + const element = window.document.createElement("div"); + element.setAttribute("data-hf-drag-paused-timelines", "figma-demo-unlock,figma-demo-stagger"); + window.document.body.append(element); + + const pausedState: Record = { + "figma-demo-unlock": true, + "figma-demo-stagger": true, + main: true, + }; + const makeTl = (id: string) => ({ + paused: (value?: boolean) => { + if (value !== undefined) pausedState[id] = value; + return pausedState[id]!; + }, + }); + const seeks: number[] = []; + const win = element.ownerDocument.defaultView as unknown as { + __timelines?: Record; + __player?: { seek: (t: number) => void; getTime: () => number }; + }; + win.__timelines = { + "figma-demo-unlock": makeTl("figma-demo-unlock"), + "figma-demo-stagger": makeTl("figma-demo-stagger"), + main: makeTl("main"), + }; + win.__player = { seek: (t: number) => seeks.push(t), getTime: () => 3.5 }; + + resumeGsapTimelines(element); + + expect(pausedState["figma-demo-unlock"]).toBe(false); + expect(pausedState["figma-demo-stagger"]).toBe(false); + // main was NOT paused by the drag — leave its state alone + expect(pausedState["main"]).toBe(true); + expect(seeks).toEqual([3.5]); + expect(element.hasAttribute("data-hf-drag-paused-timelines")).toBe(false); + }); + + it("is a no-op without the paused-timelines attribute", () => { + const window = new Window(); + const element = window.document.createElement("div"); + window.document.body.append(element); + expect(() => resumeGsapTimelines(element)).not.toThrow(); + }); +}); diff --git a/packages/studio/src/components/editor/manualOffsetDrag.ts b/packages/studio/src/components/editor/manualOffsetDrag.ts index 75609a73c3..736719c4ea 100644 --- a/packages/studio/src/components/editor/manualOffsetDrag.ts +++ b/packages/studio/src/components/editor/manualOffsetDrag.ts @@ -561,11 +561,23 @@ export function resumeGsapTimelines(element: HTMLElement): void { if (!ids) return; const win = element.ownerDocument.defaultView as | (Window & { - __timelines?: Record void }>; + __timelines?: Record boolean }>; __player?: { seek?: (t: number) => void; getTime?: () => number }; }) | null; if (!win) return; + // Unpause exactly the timelines the drag start paused. The player seek below + // repositions them, but a seek alone leaves play-state-driven sub-composition + // timelines paused forever — the "selecting a piece kills its animation" bug: + // main survives (seek-driven every frame) while every scene timeline freezes, + // and deselecting can't recover because nothing else ever resumes them. + for (const id of ids.split(",")) { + try { + win.__timelines?.[id]?.paused?.(false); + } catch { + /* cross-origin guard */ + } + } const t = win.__player?.getTime?.() ?? 0; win.__player?.seek?.(t); }