Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Timeline delete menu and visual-mode props gate; undo HMR flag and delete logs

JonnyBurger0fd645e99453
diff --git a/packages/example/src/NewVideo.tsx b/packages/example/src/NewVideo.tsx
index b0b236152f..157bc725dd 100644
--- a/packages/example/src/NewVideo.tsx
+++ b/packages/example/src/NewVideo.tsx
@@ -19,7 +19,7 @@ export const calculateMetadataFn: CalculateMetadataFunction<
};
export const Component = () => {
- return <Video src={src} />;
+ return null;
};
export const NewVideoComp = () => {
diff --git a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts
index e278f70b31..e9d7e67a7f 100644
--- a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts
+++ b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts
@@ -85,6 +85,7 @@ export const applyVisualControlHandler: ApiHandler<
redoMessage: 'Redid visual control change',
},
entryType: 'visual-control',
+ suppressHmrOnFileRestore: true,
});
suppressUndoStackInvalidation(absolutePath);
suppressBundlerUpdateForFile(absolutePath);
diff --git a/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts b/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
index 1b87e07c95..5acce97c4c 100644
--- a/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
+++ b/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
@@ -7,13 +7,14 @@ import type {
} from '@remotion/studio-shared';
import {deleteJsxNode} from '../../codemods/delete-jsx-node';
import {writeFileAndNotifyFileWatchers} from '../../file-watcher';
+import {makeHyperlink} from '../../hyperlinks/make-link';
import type {ApiHandler} from '../api-types';
import {
printUndoHint,
pushToUndoStack,
suppressUndoStackInvalidation,
} from '../undo-stack';
-import {suppressBundlerUpdateForFile} from '../watch-ignore-next-change';
+import {warnAboutPrettierOnce} from './log-update';
export const deleteJsxNodeHandler: ApiHandler<
DeleteJsxNodeRequest,
@@ -43,15 +44,28 @@ export const deleteJsxNodeHandler: ApiHandler<
logLevel,
remotionRoot,
description: {
- undoMessage: 'Undid JSX node deletion',
- redoMessage: 'Redid JSX node deletion',
+ undoMessage: 'Undid node deletion',
+ redoMessage: 'Redid node deletion',
},
entryType: 'delete-jsx-node',
+ suppressHmrOnFileRestore: false,
});
suppressUndoStackInvalidation(absolutePath);
- suppressBundlerUpdateForFile(absolutePath);
writeFileAndNotifyFileWatchers(absolutePath, output);
+ const fileLink = makeHyperlink({
+ url: `file://${absolutePath}`,
+ text: fileRelativeToRoot,
+ fallback: fileRelativeToRoot,
+ });
+ RenderInternals.Log.info(
+ {indent: false, logLevel},
+ `${RenderInternals.chalk.blueBright(`${fileLink}:`)} Deleted node`,
+ );
+ if (!formatted) {
+ warnAboutPrettierOnce(logLevel);
+ }
+
RenderInternals.Log.verbose(
{indent: false, logLevel},
`[delete-jsx-node] Wrote ${fileRelativeToRoot}${formatted ? ' (formatted)' : ''}`,
diff --git a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
index c77a904317..a6ca3e3da2 100644
--- a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
@@ -80,6 +80,7 @@ export const saveSequencePropsHandler: ApiHandler<
redoMessage: `Redid ${redoPropChange}`,
},
entryType: 'sequence-props',
+ suppressHmrOnFileRestore: true,
});
suppressUndoStackInvalidation(absolutePath);
suppressBundlerUpdateForFile(absolutePath);
diff --git a/packages/studio-server/src/preview-server/routes/update-default-props.ts b/packages/studio-server/src/preview-server/routes/update-default-props.ts
index fcca592120..58fa548def 100644
--- a/packages/studio-server/src/preview-server/routes/update-default-props.ts
+++ b/packages/studio-server/src/preview-server/routes/update-default-props.ts
@@ -58,6 +58,7 @@ export const updateDefaultPropsHandler: ApiHandler<
redoMessage: `Redid default props update for "${compositionId}"`,
},
entryType: 'default-props',
+ suppressHmrOnFileRestore: true,
});
suppressUndoStackInvalidation(projectInfo.rootFile);
suppressBundlerUpdateForFile(projectInfo.rootFile);
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index 4d1e2ac349..5a9e2d9c14 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -27,6 +27,8 @@ type UndoEntry = {
filePath: string;
oldContents: string;
description: UndoEntryDescription;
+ /** When true, undo/redo file restores call `suppressBundlerUpdateForFile` (skip HMR refresh). */
+ suppressHmrOnFileRestore: boolean;
} & (
| {entryType: 'visual-control'}
| {entryType: 'default-props'}
@@ -65,6 +67,7 @@ export function pushToUndoStack({
remotionRoot,
description,
entryType,
+ suppressHmrOnFileRestore,
}: {
filePath: string;
oldContents: string;
@@ -72,10 +75,17 @@ export function pushToUndoStack({
remotionRoot: string;
description: UndoEntryDescription;
entryType: UndoEntryType;
+ suppressHmrOnFileRestore: boolean;
}) {
storedLogLevel = logLevel;
storedRemotionRoot = remotionRoot;
- undoStack.push({filePath, oldContents, description, entryType});
+ undoStack.push({
+ filePath,
+ oldContents,
+ description,
+ entryType,
+ suppressHmrOnFileRestore,
+ });
if (undoStack.length > MAX_ENTRIES) {
undoStack.shift();
}
@@ -104,13 +114,26 @@ export function printUndoHint(logLevel: LogLevel) {
}
}
-export function pushToRedoStack(
- filePath: string,
- oldContents: string,
- description: UndoEntryDescription,
- entryType: UndoEntryType,
-) {
- redoStack.push({filePath, oldContents, description, entryType});
+export function pushToRedoStack({
+ filePath,
+ oldContents,
+ description,
+ entryType,
+ suppressHmrOnFileRestore,
+}: {
+ filePath: string;
+ oldContents: string;
+ description: UndoEntryDescription;
+ entryType: UndoEntryType;
+ suppressHmrOnFileRestore: boolean;
+}) {
+ redoStack.push({
+ filePath,
+ oldContents,
+ description,
+ entryType,
+ suppressHmrOnFileRestore,
+ });
if (redoStack.length > MAX_ENTRIES) {
redoStack.shift();
}
@@ -263,10 +286,14 @@ export function popUndo(): {success: true} | {success: false; reason: string} {
oldContents: currentContents,
description: entry.description,
entryType: entry.entryType,
+ suppressHmrOnFileRestore: entry.suppressHmrOnFileRestore,
});
suppressUndoStackInvalidation(entry.filePath);
- suppressBundlerUpdateForFile(entry.filePath);
+ if (entry.suppressHmrOnFileRestore) {
+ suppressBundlerUpdateForFile(entry.filePath);
+ }
+
writeFileAndNotifyFileWatchers(entry.filePath, entry.oldContents);
RenderInternals.Log.verbose(
@@ -298,10 +325,13 @@ export function popRedo(): {success: true} | {success: false; reason: string} {
oldContents: currentContents,
description: entry.description,
entryType: entry.entryType,
+ suppressHmrOnFileRestore: entry.suppressHmrOnFileRestore,
});
suppressUndoStackInvalidation(entry.filePath);
- suppressBundlerUpdateForFile(entry.filePath);
+ if (entry.suppressHmrOnFileRestore) {
+ suppressBundlerUpdateForFile(entry.filePath);
+ }
writeFileAndNotifyFileWatchers(entry.filePath, entry.oldContents);
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index fbaa168c52..a590e44a9a 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -7,7 +7,11 @@ import {
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
} from '../../helpers/timeline-layout';
+import {callApi} from '../call-api';
+import {ContextMenu} from '../ContextMenu';
import {ExpandedTracksContext} from '../ExpandedTracksProvider';
+import type {ComboboxValue} from '../NewComposition/ComboBox';
+import {showNotification} from '../Notifications/NotificationCenter';
import {TimelineExpandedSection} from './TimelineExpandedSection';
import {TimelineLayerEye} from './TimelineLayerEye';
import {TimelineStack} from './TimelineStack';
@@ -55,7 +59,82 @@ export const TimelineListItem: React.FC<{
const {expandedTracks, toggleTrack} = useContext(ExpandedTracksContext);
const originalLocation = useResolvedStack(sequence.stack ?? null);
- const nodePath = useSequencePropsSubscription(sequence, originalLocation);
+ const nodePath = useSequencePropsSubscription(
+ sequence,
+ originalLocation,
+ visualModeEnabled,
+ );
+
+ const validatedLocation = useMemo(() => {
+ if (
+ !originalLocation ||
+ !originalLocation.source ||
+ !originalLocation.line
+ ) {
+ return null;
+ }
+
+ return {
+ source: originalLocation.source,
+ line: originalLocation.line,
+ column: originalLocation.column ?? 0,
+ };
+ }, [originalLocation]);
+
+ const hasSequencePropsStatus = Boolean(nodePath);
+
+ const onDeleteSequenceFromSource = useCallback(async () => {
+ if (!validatedLocation?.source || !nodePath) {
+ return;
+ }
+
+ try {
+ const result = await callApi('/api/delete-jsx-node', {
+ fileName: validatedLocation.source,
+ nodePath,
+ });
+ if (result.success) {
+ showNotification('Removed sequence from source file', 2000);
+ } else {
+ showNotification(result.reason, 4000);
+ }
+ } catch (err) {
+ showNotification((err as Error).message, 4000);
+ }
+ }, [nodePath, validatedLocation?.source]);
+
+ const contextMenuValues = useMemo((): ComboboxValue[] => {
+ if (
+ !visualModeEnabled ||
+ !sequence.controls ||
+ !hasSequencePropsStatus ||
+ !validatedLocation?.source
+ ) {
+ return [];
+ }
+
+ return [
+ {
+ type: 'item',
+ id: 'delete-sequence',
+ keyHint: null,
+ label: 'Delete',
+ leftItem: null,
+ onClick: () => {
+ onDeleteSequenceFromSource();
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ value: 'delete-sequence',
+ },
+ ];
+ }, [
+ hasSequencePropsStatus,
+ onDeleteSequenceFromSource,
+ sequence.controls,
+ validatedLocation?.source,
+ visualModeEnabled,
+ ]);
const isExpanded =
visualModeEnabled && (expandedTracks[sequence.id] ?? false);
@@ -110,44 +189,52 @@ export const TimelineListItem: React.FC<{
};
}, [isExpanded]);
+ const trackRow = (
+ <div style={outer}>
+ <TimelineLayerEye
+ type={sequence.type === 'audio' ? 'speaker' : 'eye'}
+ hidden={isItemHidden}
+ onInvoked={onToggleVisibility}
+ />
+ <div style={padder} />
+ {sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}
+ {visualModeEnabled ? (
+ sequence.controls ? (
+ <button
+ type="button"
+ style={arrowStyle}
+ onClick={onToggleExpand}
+ aria-expanded={isExpanded}
+ aria-label={`${isExpanded ? 'Collapse' : 'Expand'} track`}
+ >
+ <svg
+ width="12"
+ height="12"
+ viewBox="0 0 8 8"
+ style={{display: 'block'}}
+ >
+ <path d="M2 1L6 4L2 7Z" fill="white" />
+ </svg>
+ </button>
+ ) : (
+ <div style={arrowButton} />
+ )
+ ) : null}
+ <TimelineStack
+ sequence={sequence}
+ isCompact={isCompact}
+ originalLocation={originalLocation}
+ />
+ </div>
+ );
+
return (
<>
- <div style={outer}>
- <TimelineLayerEye
- type={sequence.type === 'audio' ? 'speaker' : 'eye'}
- hidden={isItemHidden}
- onInvoked={onToggleVisibility}
- />
- <div style={padder} />
- {sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}
- {visualModeEnabled ? (
- sequence.controls ? (
- <button
- type="button"
- style={arrowStyle}
- onClick={onToggleExpand}
- aria-expanded={isExpanded}
- aria-label={`${isExpanded ? 'Collapse' : 'Expand'} track`}
- >
- <svg
- width="12"
- height="12"
- viewBox="0 0 8 8"
- style={{display: 'block'}}
- >
- <path d="M2 1L6 4L2 7Z" fill="white" />
- </svg>
- </button>
- ) : (
- <div style={arrowButton} />
- )
- ) : null}
- <TimelineStack
- sequence={sequence}
- isCompact={isCompact}
- originalLocation={originalLocation}
- />
- </div>
+ {contextMenuValues.length > 0 ? (
+ <ContextMenu values={contextMenuValues}>{trackRow}</ContextMenu>
+ ) : (
+ trackRow
+ )}
{visualModeEnabled && isExpanded && sequence.controls ? (
<TimelineExpandedSection
sequence={sequence}
diff --git a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
index 92064b3fae..9094c92fcb 100644
--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
@@ -1,5 +1,12 @@
import type {EventSourceEvent, SequenceNodePath} from '@remotion/studio-shared';
-import {useCallback, useContext, useEffect, useMemo, useRef} from 'react';
+import {
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from 'react';
import {Internals, type CanUpdateSequencePropStatus} from 'remotion';
import type {TSequence} from 'remotion';
import type {OriginalPosition} from '../../error-overlay/react-overlay/utils/get-source-map';
@@ -10,6 +17,7 @@ import {callApi} from '../call-api';
export const useSequencePropsSubscription = (
sequence: TSequence,
originalLocation: OriginalPosition | null,
+ visualModeEnabled: boolean,
): SequenceNodePath | null => {
const {setCodeValues} = useContext(Internals.VisualModeOverridesContext);
const overrideId = sequence.controls?.overrideId ?? null;
@@ -68,8 +76,14 @@ export const useSequencePropsSubscription = (
currentLocationColumn.current = locationColumn;
const nodePathRef = useRef<SequenceNodePath | null>(null);
+ const [nodePath, setNodePath] = useState<SequenceNodePath | null>(null);
const isMountedRef = useRef(true);
+ const setNodePathBoth = useCallback((next: SequenceNodePath | null) => {
+ nodePathRef.current = next;
+ setNodePath(next);
+ }, []);
+
useEffect(() => {
isMountedRef.current = true;
return () => {
@@ -78,6 +92,12 @@ export const useSequencePropsSubscription = (
}, []);
useEffect(() => {
+ if (!visualModeEnabled) {
+ setPropStatusesForSequence(null);
+ setNodePathBoth(null);
+ return;
+ }
+
if (
!clientId ||
!locationSource ||
@@ -86,6 +106,7 @@ export const useSequencePropsSubscription = (
!schemaKeysString
) {
setPropStatusesForSequence(null);
+ setNodePathBoth(null);
return;
}
@@ -108,15 +129,15 @@ export const useSequencePropsSubscription = (
}
if (result.canUpdate) {
- nodePathRef.current = result.nodePath;
+ setNodePathBoth(result.nodePath);
setPropStatusesForSequence(result.props);
} else {
- nodePathRef.current = null;
+ setNodePathBoth(null);
setPropStatusesForSequence(null);
}
})
.catch((err) => {
- nodePathRef.current = null;
+ setNodePathBoth(null);
Internals.Log.error(err);
setPropStatusesForSequence(null);
});
@@ -129,7 +150,7 @@ export const useSequencePropsSubscription = (
setPropStatusesForSequence(null);
}
- nodePathRef.current = null;
+ setNodePathBoth(null);
if (currentNodePath) {
callApi('/api/unsubscribe-from-sequence-props', {
fileName: locationSource,
@@ -141,15 +162,21 @@ export const useSequencePropsSubscription = (
}
};
}, [
+ visualModeEnabled,
clientId,
locationSource,
locationLine,
locationColumn,
schemaKeysString,
setPropStatusesForSequence,
+ setNodePathBoth,
]);
useEffect(() => {
+ if (!visualModeEnabled) {
+ return;
+ }
+
if (!locationSource || !locationLine || locationColumn === null) {
return;
}
@@ -171,6 +198,7 @@ export const useSequencePropsSubscription = (
setPropStatusesForSequence(event.result.props);
} else {
setPropStatusesForSequence(null);
+ setNodePathBoth(null);
}
};
@@ -179,12 +207,14 @@ export const useSequencePropsSubscription = (
unsub();
};
}, [
+ visualModeEnabled,
locationSource,
locationLine,
locationColumn,
subscribeToEvent,
setPropStatusesForSequence,
+ setNodePathBoth,
]);
- return nodePathRef.current;
+ return nodePath;
};