Skip to content

🎥 Make videos programmatically with React

Apply canvas save batching consistently and document SDK transactions

Jonny Burger477e4202c1d4
diff --git a/packages/docs/docs/sdk/canvas.mdx b/packages/docs/docs/sdk/canvas.mdx
index 254335570e..d069df2b06 100644
--- a/packages/docs/docs/sdk/canvas.mdx
+++ b/packages/docs/docs/sdk/canvas.mdx
@@ -57,15 +57,17 @@ Enables moving elements on the canvas. Dragging a selected outline moves every s
While the gesture is in progress, the new `style.translate` values are previewed through [`controller.overrides`](/docs/sdk/create-canvas-controller#overrides). When the gesture ends with a changed value, the callback receives one `CanvasSequencePropChange` per moved source node with `nodePathInfo`, the schema `key`, the `value` and the element's `schema`. A change with `type: 'static'` also carries the schema `defaultValue`; write it with [`updateNodeProps()`](/docs/codemods/update-node-props). A change with `type: 'keyframe'` carries the `frame` at which to add a keyframe with [`updateNodeKeyframes()`](/docs/codemods/update-node-keyframes); it is reported for props that [`getSequencePropStatuses`](#getsequencepropstatuses) describes as keyframed. Clear the overrides once the update is applied; until then, the canvas keeps showing the new position.
+The callback receives all static and keyframed changes from one gesture together. Persist the full batch as one undoable edit so one undo restores every moved element.
+
```tsx twoslash title="Persisting a move"
// @moduleResolution: bundler
import type {CanvasController, CanvasSequencePropChange} from '@remotion/sdk';
declare const controller: CanvasController;
-declare const persist: (change: CanvasSequencePropChange) => Promise<void>;
+declare const persist: (changes: readonly CanvasSequencePropChange[]) => Promise<void>;
// ---cut---
export const onSequencePropsChange = async (changes: readonly CanvasSequencePropChange[]) => {
+ await persist(changes);
for (const change of changes) {
- await persist(change);
controller.overrides.clear(change.nodePathInfo);
}
};
diff --git a/packages/sdk/src/canvas.tsx b/packages/sdk/src/canvas.tsx
index aa18d4de0f..05e8c19c22 100644
--- a/packages/sdk/src/canvas.tsx
+++ b/packages/sdk/src/canvas.tsx
@@ -34,8 +34,9 @@ export type CanvasProps<
readonly resolveSequenceNodePathInfo?: CanvasSequenceNodePathResolver;
/**
* Enables moving selected outlines by dragging them or pressing the arrow
- * keys. Called with the resulting prop values once a gesture ends; the
- * values stay previewed through `controller.overrides` until you clear them.
+ * keys. Called once with all static and keyframed prop changes when a
+ * gesture ends. Persist the full batch as one undoable edit. The values
+ * stay previewed through `controller.overrides` until you clear them.
*/
readonly onSequencePropsChange?: CanvasSequencePropsChangeHandler;
/**
diff --git a/packages/sdk/src/sequence-props-change.ts b/packages/sdk/src/sequence-props-change.ts
index 030cc5d84f..6d9254bae2 100644
--- a/packages/sdk/src/sequence-props-change.ts
+++ b/packages/sdk/src/sequence-props-change.ts
@@ -25,6 +25,10 @@ export type CanvasSequencePropChange =
readonly frame: number;
});
+/**
+ * Receives all static and keyframed prop changes from one canvas gesture in
+ * one call. Persist the full batch as one undoable edit.
+ */
export type CanvasSequencePropsChangeHandler = (
changes: readonly CanvasSequencePropChange[],
) => void;
diff --git a/packages/studio/src/components/SelectedOutlineCropControls.tsx b/packages/studio/src/components/SelectedOutlineCropControls.tsx
index 23176eefdb..512d19cc1e 100644
--- a/packages/studio/src/components/SelectedOutlineCropControls.tsx
+++ b/packages/studio/src/components/SelectedOutlineCropControls.tsx
@@ -28,7 +28,6 @@ import {
type SelectedOutlineTarget,
} from './selected-outline-types';
import {getUvCoordinateForPoint} from './selected-outline-uv';
-import {callAddKeyframes} from './Timeline/call-add-keyframe';
import {commitPendingInspectorFields} from './Timeline/focus-inspector-field';
import {resolveKeyframeSourceFrame} from './Timeline/get-timeline-keyframes';
import {saveSequenceProps} from './Timeline/save-sequence-prop';
@@ -310,25 +309,15 @@ const CropHandle: React.FC<{
change.type === 'keyframed',
);
- const promise =
- staticChanges.length === 0
- ? callAddKeyframes({
- sequenceKeyframes: keyframedChanges,
- effectKeyframes: [],
- setPropStatuses,
- clientId: cropDrag.clientId,
- })
- : saveSequenceProps({
- changes: staticChanges,
- addedKeyframes: keyframedChanges,
- movedKeyframes: null,
- setPropStatuses,
- clientId: cropDrag.clientId,
- undoLabel: 'Crop sequence',
- redoLabel: 'Crop sequence back',
- });
-
- promise
+ saveSequenceProps({
+ changes: staticChanges,
+ addedKeyframes: keyframedChanges,
+ movedKeyframes: null,
+ setPropStatuses,
+ clientId: cropDrag.clientId,
+ undoLabel: 'Crop sequence',
+ redoLabel: 'Crop sequence back',
+ })
.catch((err) => {
showNotification(
`Could not save crop: ${
diff --git a/packages/studio/src/components/SelectedOutlineTransformOriginHandle.tsx b/packages/studio/src/components/SelectedOutlineTransformOriginHandle.tsx
index 9461207aaf..348d70584d 100644
--- a/packages/studio/src/components/SelectedOutlineTransformOriginHandle.tsx
+++ b/packages/studio/src/components/SelectedOutlineTransformOriginHandle.tsx
@@ -29,7 +29,6 @@ import {
getUvCoordinateForPoint,
getUvHandlePosition,
} from './selected-outline-uv';
-import {callAddKeyframes} from './Timeline/call-add-keyframe';
import {resolveKeyframeSourceFrame} from './Timeline/get-timeline-keyframes';
import {saveSequenceProps} from './Timeline/save-sequence-prop';
import {parseCssRotation} from './Timeline/timeline-rotation-utils';
@@ -314,25 +313,15 @@ export const SelectedOutlineTransformOriginHandle: React.FC<{
return;
}
- const promise =
- staticChanges.length === 0
- ? callAddKeyframes({
- sequenceKeyframes: keyframedChanges,
- effectKeyframes: [],
- setPropStatuses,
- clientId: transformOriginDrag.clientId,
- })
- : saveSequenceProps({
- changes: staticChanges,
- addedKeyframes: keyframedChanges,
- movedKeyframes: null,
- setPropStatuses,
- clientId: transformOriginDrag.clientId,
- undoLabel: 'Move transform origin',
- redoLabel: 'Move transform origin back',
- });
-
- promise
+ saveSequenceProps({
+ changes: staticChanges,
+ addedKeyframes: keyframedChanges,
+ movedKeyframes: null,
+ setPropStatuses,
+ clientId: transformOriginDrag.clientId,
+ undoLabel: 'Move transform origin',
+ redoLabel: 'Move transform origin back',
+ })
.catch((err) => {
showNotification(
`Could not save transform origin: ${
diff --git a/packages/template-vibe-code/README.md b/packages/template-vibe-code/README.md
index 65742f7a67..413ffb0ff3 100644
--- a/packages/template-vibe-code/README.md
+++ b/packages/template-vibe-code/README.md
@@ -68,7 +68,9 @@ The browser bundler records where every JSX element was written, and the Canvas
Dragging a value in the inspector or a track in the timeline does not rewrite the source on every pointer move. The editor previews the value on the canvas with [`controller.overrides`](https://www.remotion.dev/docs/sdk/create-canvas-controller#overrides) and writes it with a codemod once the gesture ends. The preview stays in place until the recompiled project is running, so the canvas never flashes the old value.
-Moving an outline on the canvas works the same way, but the Canvas owns the gesture: it previews `style.translate` while dragging and reports the final values through the [`onSequencePropsChange`](https://www.remotion.dev/docs/sdk/canvas#onsequencepropschange) prop. The editor writes them with `updateMultipleNodeProps()` in one undoable step and releases the previews once the new bundle runs. Before a move starts, the Canvas asks the editor through [`getSequencePropStatuses`](https://www.remotion.dev/docs/sdk/canvas#getsequencepropstatuses) how the position is written: a position animated with `interpolate()` gets a keyframe at the playhead via `updateNodeKeyframes()`, and a position computed in code cannot be moved.
+Moving an outline on the canvas works the same way, but the Canvas owns the gesture: it previews `style.translate` while dragging and reports the final values through the [`onSequencePropsChange`](https://www.remotion.dev/docs/sdk/canvas#onsequencepropschange) prop. Before a move starts, the Canvas asks the editor through [`getSequencePropStatuses`](https://www.remotion.dev/docs/sdk/canvas#getsequencepropstatuses) how the position is written: a position animated with `interpolate()` gets a keyframe at the playhead via `updateNodeKeyframes()`, and a position computed in code cannot be moved.
+
+The callback reports static and keyframed changes together. The editor applies `updateMultipleNodeProps()` and `updateNodeKeyframes()` to the same project before committing the resulting files in one undoable step. One undo or redo restores or reapplies the entire mixed selection. The previews are released once the new bundle runs.
### Keyframes