Skip to content

Commit 64b94eb

Browse files
vanceingallsclaude
andauthored
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 <[email protected]>
1 parent 7e3bcd9 commit 64b94eb

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎packages/studio/src/components/editor/manualOffsetDrag.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Window } from "happy-dom";
22
import { describe, expect, it } from "vitest";
33
import {
44
applyManualOffsetDragCommit,
5+
resumeGsapTimelines,
56
applyManualOffsetDragDraft,
67
applyManualOffsetDragMatrix,
78
createManualOffsetDragMember,
@@ -447,3 +448,51 @@ describe("GSAP-element drag — dot-a flies regressions", () => {
447448
expect(element.style.getPropertyValue("transform")).toMatch(/translate\(/);
448449
});
449450
});
451+
452+
describe("resumeGsapTimelines", () => {
453+
it("unpauses exactly the timelines the drag start paused, then re-seeks the player", () => {
454+
const window = new Window();
455+
const element = window.document.createElement("div");
456+
element.setAttribute("data-hf-drag-paused-timelines", "figma-demo-unlock,figma-demo-stagger");
457+
window.document.body.append(element);
458+
459+
const pausedState: Record<string, boolean> = {
460+
"figma-demo-unlock": true,
461+
"figma-demo-stagger": true,
462+
main: true,
463+
};
464+
const makeTl = (id: string) => ({
465+
paused: (value?: boolean) => {
466+
if (value !== undefined) pausedState[id] = value;
467+
return pausedState[id]!;
468+
},
469+
});
470+
const seeks: number[] = [];
471+
const win = element.ownerDocument.defaultView as unknown as {
472+
__timelines?: Record<string, unknown>;
473+
__player?: { seek: (t: number) => void; getTime: () => number };
474+
};
475+
win.__timelines = {
476+
"figma-demo-unlock": makeTl("figma-demo-unlock"),
477+
"figma-demo-stagger": makeTl("figma-demo-stagger"),
478+
main: makeTl("main"),
479+
};
480+
win.__player = { seek: (t: number) => seeks.push(t), getTime: () => 3.5 };
481+
482+
resumeGsapTimelines(element);
483+
484+
expect(pausedState["figma-demo-unlock"]).toBe(false);
485+
expect(pausedState["figma-demo-stagger"]).toBe(false);
486+
// main was NOT paused by the drag — leave its state alone
487+
expect(pausedState["main"]).toBe(true);
488+
expect(seeks).toEqual([3.5]);
489+
expect(element.hasAttribute("data-hf-drag-paused-timelines")).toBe(false);
490+
});
491+
492+
it("is a no-op without the paused-timelines attribute", () => {
493+
const window = new Window();
494+
const element = window.document.createElement("div");
495+
window.document.body.append(element);
496+
expect(() => resumeGsapTimelines(element)).not.toThrow();
497+
});
498+
});

‎packages/studio/src/components/editor/manualOffsetDrag.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,23 @@ export function resumeGsapTimelines(element: HTMLElement): void {
561561
if (!ids) return;
562562
const win = element.ownerDocument.defaultView as
563563
| (Window & {
564-
__timelines?: Record<string, { pause?: () => void }>;
564+
__timelines?: Record<string, { paused?: (value?: boolean) => boolean }>;
565565
__player?: { seek?: (t: number) => void; getTime?: () => number };
566566
})
567567
| null;
568568
if (!win) return;
569+
// Unpause exactly the timelines the drag start paused. The player seek below
570+
// repositions them, but a seek alone leaves play-state-driven sub-composition
571+
// timelines paused forever — the "selecting a piece kills its animation" bug:
572+
// main survives (seek-driven every frame) while every scene timeline freezes,
573+
// and deselecting can't recover because nothing else ever resumes them.
574+
for (const id of ids.split(",")) {
575+
try {
576+
win.__timelines?.[id]?.paused?.(false);
577+
} catch {
578+
/* cross-origin guard */
579+
}
580+
}
569581
const t = win.__player?.getTime?.() ?? 0;
570582
win.__player?.seek?.(t);
571583
}

0 commit comments

Comments
 (0)