Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): a rotation saves through its press route; a host hook reloads only the host's way (#4961)
Miguel Ángel910677259364
diff --git a/packages/studio/src/components/editor/rotationDraft.ts b/packages/studio/src/components/editor/rotationDraft.tsindex 6242a6e695..d4e35621e3 100644--- a/packages/studio/src/components/editor/rotationDraft.ts+++ b/packages/studio/src/components/editor/rotationDraft.ts@@ -51,7 +51,8 @@ export interface CssRotationTarget {inline: boolean;}-export type RotationCommit = { angle: number; plain?: CssRotationTarget };+export type PressChoseGsap = null;+export type RotationCommit = { angle: number; plain?: CssRotationTarget | PressChoseGsap };const TRANSLATE = /^translate(?:3d|X|Y|Z)?\(/i;const OWN_TURN = /^rotate\(\s*-?[\d.]+(?:e[+-]?\d+)?deg\s*\)$/i;diff --git a/packages/studio/src/components/editor/useDomEditOverlayGestures.ts b/packages/studio/src/components/editor/useDomEditOverlayGestures.tsindex c7c6893844..70a72a1bf6 100644--- a/packages/studio/src/components/editor/useDomEditOverlayGestures.ts+++ b/packages/studio/src/components/editor/useDomEditOverlayGestures.ts@@ -442,7 +442,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu}// Hold the final angle while the commit lands.applyRotationDraft(sel.element, finalRotation.angle, g.plainRotation);- const commit = g.plainRotation ? { ...finalRotation, plain: g.plainRotation } : finalRotation;+ const commit = { ...finalRotation, plain: g.plainRotation };void Promise.resolve(opts.onRotationCommitRef.current(sel, commit)).then((result) => trackPreviewEditResult("rotate", "drag", result)).catch((error) => {diff --git a/packages/studio/src/hooks/plainRotation.ts b/packages/studio/src/hooks/plainRotation.tsindex f96cb0f7de..efd1c07cee 100644--- a/packages/studio/src/hooks/plainRotation.ts+++ b/packages/studio/src/hooks/plainRotation.ts@@ -27,7 +27,11 @@ export function savePlainRotation(? buildClearRotationPatches(element): [];if (patches.length) clearStudioRotation(element);- const drawn = applyCssRotation(element, next.angle, patches.length ? undefined : next.plain);+ const drawn = applyCssRotation(+ element,+ next.angle,+ patches.length ? undefined : (next.plain ?? undefined),+ );patches.push(...drawn);const turn = drawn.at(-1)!;return commitPositionPatchToHtml(selection, patches, {diff --git a/packages/studio/src/hooks/useDomGeometryCommit.test.tsx b/packages/studio/src/hooks/useDomGeometryCommit.test.tsxindex c31af2e0c9..6d7f6215f9 100644--- a/packages/studio/src/hooks/useDomGeometryCommit.test.tsx+++ b/packages/studio/src/hooks/useDomGeometryCommit.test.tsx@@ -1,7 +1,7 @@// @vitest-environment happy-domimport { act, createElement, useRef } from "react";import { createRoot } from "react-dom/client";-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, expectTypeOf, it, vi } from "vitest";import {useDomGeometryCommit,usePlayerStore,@@ -108,6 +108,10 @@ afterEach(() => {});describe("useDomGeometryCommit, from the package entry", () => {+ it("takes the host's own preview reload, with no fallback", () => {+ expectTypeOf<UseDomGeometryCommitOptions["reloadPreview"]>().toEqualTypeOf<() => void>();+ });+it("plugs into DomEditOverlay and saves a move as one GSAP write and one undo step", async () => {const mutations = stubServer();const { element, recordEdit, hook, unmount } = renderHost();diff --git a/packages/studio/src/hooks/useDomGeometryCommit.ts b/packages/studio/src/hooks/useDomGeometryCommit.tsindex b623c59d96..af139744dc 100644--- a/packages/studio/src/hooks/useDomGeometryCommit.ts+++ b/packages/studio/src/hooks/useDomGeometryCommit.ts@@ -26,8 +26,8 @@ import { useMountEffect } from "./useMountEffect";* mounts; drain `waitForPendingSaves` before switching projects.*/export interface UseDomGeometryCommitOptions extends UseDomStyleCommitOptions {- /** Called when a save cannot patch the preview in place; defaults to reloading the iframe. */- reloadPreview?: () => void;+ /** Reloads the host's preview when a save cannot patch it in place. */+ reloadPreview: () => void;}export interface DomGeometryCommits {@@ -71,17 +71,13 @@ export function useDomGeometryCommit({projectIdRef.current = projectId;const pending = useRef(new Set<Promise<GeometryCommitResult | undefined>>()).current;const editHistory = useMemo(() => ({ recordEdit }), [recordEdit]);- const reload = useCallback(- () => (reloadPreview ? reloadPreview() : iframeRef.current?.contentWindow?.location.reload()),- [reloadPreview, iframeRef],- );const { bump: bumpGsapCache } = useGsapCacheVersion();const gsap = useGsapScriptCommits({projectIdRef,activeCompPath,previewIframeRef: iframeRef,editHistory,- reloadPreview: reload,+ reloadPreview,onCacheInvalidate: bumpGsapCache,showToast,writeProjectFile,diff --git a/packages/studio/src/hooks/useGsapAwareEditing.test.tsx b/packages/studio/src/hooks/useGsapAwareEditing.test.tsxindex ac469a77c5..cd00c9a97c 100644--- a/packages/studio/src/hooks/useGsapAwareEditing.test.tsx+++ b/packages/studio/src/hooks/useGsapAwareEditing.test.tsx@@ -312,6 +312,15 @@ describe("useGsapAwareEditing rotation routing", () => {act(() => h.root.unmount());});+ it("saves a turn the press sent down the GSAP route there, even once the element looks GSAP-free", async () => {+ vi.mocked(tryGsapRotationIntercept).mockResolvedValue({ status: "persisted" });+ const h = rotate(document.createElement("div"));+ await act(() => h.rotationCommit(h.box, { angle: 55, plain: null }));+ expect(tryGsapRotationIntercept).toHaveBeenCalledTimes(1);+ expect(h.handleDomRotationCommit).not.toHaveBeenCalled();+ act(() => h.root.unmount());+ });+it("saves a turn the press drew as CSS by the CSS writer, even once a GSAP tween turns the element", async () => {const element = document.createElement("div");const h = rotate(element);diff --git a/packages/studio/src/hooks/useGsapAwareEditing.ts b/packages/studio/src/hooks/useGsapAwareEditing.tsindex fd6ca6ada8..15a9b64470 100644--- a/packages/studio/src/hooks/useGsapAwareEditing.ts+++ b/packages/studio/src/hooks/useGsapAwareEditing.ts@@ -364,7 +364,7 @@ export function useGsapAwareEditing({const handleGsapAwareRotationCommit = useCallback(async (selection: DomEditSelection, next: RotationCommit) => {const writes = observeGsapGesture(gsapCommitMutation);- if (next.plain || editsPlainCss(selection.element, "rotate")) {+ if (next.plain === undefined ? editsPlainCss(selection.element, "rotate") : next.plain) {const result = await handleDomRotationCommit(selection, next);return writes.finish(result?.changed === true);}