Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): don't crash resizing an element whose keyframes were removed
Miguel Angel Simon Sierradff3634ea89d
diff --git a/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.test.ts b/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.test.tsindex aff002556b..9eddc4ab5a 100644--- a/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.test.ts+++ b/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.test.ts@@ -133,4 +133,30 @@ describe("commitWholePropertyOffset", () => {});expect(keyframes[1]).toEqual({ percentage: 100, properties: { x: 120, opacity: 0.5 } });});++ it("persists a flat update instead of crashing when the tween has no synthesizable shape", async () => {+ // Regression: removeAllKeyframesFromScript collapses a keyframed tween into a+ // zero-duration immediateRender hold — synthesizeFlatTweenKeyframes treats that+ // as a static hold (returns null), so `kfs` is empty. Resizing this element with+ // auto-keyframe off used to call `kfs.reduce(...)` with no initial value, which+ // throws "Reduce of empty array with no initial value".+ const anim = {+ id: "#box-hold",+ targetSelector: "#box",+ method: "to",+ resolvedStart: 0,+ duration: 0,+ properties: { width: 200 },+ extras: { immediateRender: "__raw:true" },+ } as unknown as GsapAnimation;++ const { mutations, callbacks } = recordingCallbacks();+ await expect(+ commitWholePropertyOffset(selection(), anim, { width: 300 }, 0, null, callbacks, "Resize"),+ ).resolves.toBeUndefined();++ expect(mutations).toEqual([+ { type: "update-properties", animationId: "#box-hold", properties: { width: 300 } },+ ]);+ });});diff --git a/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.ts b/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.tsindex 6363363c45..fff1f841b2 100644--- a/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.ts+++ b/packages/studio/src/hooks/gsapWholePropertyOffsetCommit.ts@@ -43,9 +43,18 @@ export async function commitWholePropertyOffset(typeof props[key] === "number" ? (props[key] as number) : (PROPERTY_DEFAULTS[key] ?? 0);const kfs =- effectiveAnim.keyframes?.keyframes ??- synthesizeFlatTweenKeyframes(effectiveAnim)?.keyframes ??- [];+ effectiveAnim.keyframes?.keyframes ?? synthesizeFlatTweenKeyframes(effectiveAnim)?.keyframes;+ if (!kfs || kfs.length === 0) {+ // A `to()`/`from()` collapsed to a zero-duration immediateRender hold (what+ // removeAllKeyframesFromScript leaves behind) has no shape to preserve —+ // just persist the flat value instead of replacing with an empty keyframe list.+ await callbacks.commitMutation(+ selection,+ { type: "update-properties", animationId: effectiveAnim.id, properties: newValues },+ { label, softReload: true },+ );+ return;+ }const nearest = kfs.reduce((best, kf) =>Math.abs(kf.percentage - currentPct) < Math.abs(best.percentage - currentPct) ? kf : best,);