Skip to content

🎥 Make videos programmatically with React

huuge refactor

JonnyBurgercd4f46355418
diff --git a/packages/core/src/SequenceManager.tsx b/packages/core/src/SequenceManager.tsx
index 17d1ca9536..2f147e8156 100644
--- a/packages/core/src/SequenceManager.tsx
+++ b/packages/core/src/SequenceManager.tsx
@@ -19,10 +19,6 @@ export type SequenceManagerContext = {
export type SequenceNodePath = Array<string | number>;
-const nodePathToString = (nodePath: SequenceNodePath): string => {
- return nodePath.join('.');
-};
-
export const SequenceManager = React.createContext<SequenceManagerContext>({
registerSequence: () => {
throw new Error('SequenceManagerContext not initialized');
@@ -58,23 +54,23 @@ export type VisualModeDragOverrides = {
export type VisualModeSetters = {
setDragOverrides: (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
key: string,
value: unknown,
) => void;
- clearDragOverrides: (nodePath: SequenceNodePath) => void;
+ clearDragOverrides: (nodePath: SequencePropsSubscriptionKey) => void;
setEffectDragOverrides: (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
key: string,
value: unknown,
) => void;
clearEffectDragOverrides: (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
) => void;
setCodeValues: (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
values: (
prev: CanUpdateSequencePropsResponse,
) => CanUpdateSequencePropsResponse,
@@ -112,11 +108,17 @@ export type CanUpdateSequencePropsResponse =
| CanUpdateSequencePropsResponseTrue
| CanUpdateSequencePropsResponseFalse;
+export const makeSequencePropsSubscriptionKey = (
+ key: SequencePropsSubscriptionKey,
+): string => {
+ return `${key.nodePath.join('.')}.${key.sequenceKeys.join('.')}.${key.effectKeys.map((keys) => keys.join('.')).join('.')}`;
+};
+
const getCodeValuesCtx = (
codeValues: CodeValues,
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
) => {
- const status = codeValues[nodePathToString(nodePath)];
+ const status = codeValues[makeSequencePropsSubscriptionKey(nodePath)];
if (!status) {
return undefined;
}
@@ -134,10 +136,10 @@ const getEffectCodeValuesCtx = ({
effectIndex,
}: {
codeValues: CodeValues;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
effectIndex: number;
}) => {
- const status = codeValues[nodePathToString(nodePath)];
+ const status = codeValues[makeSequencePropsSubscriptionKey(nodePath)];
if (!status || !status.canUpdate) {
return undefined;
}
@@ -190,10 +192,18 @@ export const VisualModeSettersContext = React.createContext<VisualModeSetters>({
},
});
+export type SequencePropsSubscriptionKey = {
+ absolutePath: string;
+ nodePath: SequenceNodePath;
+ sequenceKeys: string[];
+ effectKeys: string[][];
+};
+
const effectDragOverridesKey = (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
-): string => `${nodePathToString(nodePath)}.effects.${effectIndex}`;
+): string =>
+ `${makeSequencePropsSubscriptionKey(nodePath)}.effects.${effectIndex}`;
export const SequenceManagerProvider: React.FC<{
readonly children: React.ReactNode;
@@ -208,11 +218,11 @@ export const SequenceManagerProvider: React.FC<{
const [codeValues, setCodeValuesMapState] = useState<CodeValues>({});
const setDragOverrides = useCallback(
- (nodePath: SequenceNodePath, key: string, value: unknown) => {
+ (nodePath: SequencePropsSubscriptionKey, key: string, value: unknown) => {
setControlOverrides((prev) => ({
...prev,
- [nodePathToString(nodePath)]: {
- ...prev[nodePathToString(nodePath)],
+ [makeSequencePropsSubscriptionKey(nodePath)]: {
+ ...prev[makeSequencePropsSubscriptionKey(nodePath)],
[key]: value,
},
}));
@@ -220,22 +230,25 @@ export const SequenceManagerProvider: React.FC<{
[],
);
- const clearDragOverrides = useCallback((nodePath: SequenceNodePath) => {
- setControlOverrides((prev) => {
- const key = nodePathToString(nodePath);
- if (!prev[key]) {
- return prev;
- }
+ const clearDragOverrides = useCallback(
+ (nodePath: SequencePropsSubscriptionKey) => {
+ setControlOverrides((prev) => {
+ const key = makeSequencePropsSubscriptionKey(nodePath);
+ if (!prev[key]) {
+ return prev;
+ }
- const next = {...prev};
- delete next[key];
- return next;
- });
- }, []);
+ const next = {...prev};
+ delete next[key];
+ return next;
+ });
+ },
+ [],
+ );
const setEffectDragOverrides = useCallback(
(
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
key: string,
value: unknown,
@@ -255,7 +268,7 @@ export const SequenceManagerProvider: React.FC<{
);
const clearEffectDragOverrides = useCallback(
- (nodePath: SequenceNodePath, effectIndex: number) => {
+ (nodePath: SequencePropsSubscriptionKey, effectIndex: number) => {
setEffectDragOverridesState((prev) => {
const mapKey = effectDragOverridesKey(nodePath, effectIndex);
if (!prev[mapKey]) {
@@ -272,13 +285,13 @@ export const SequenceManagerProvider: React.FC<{
const setCodeValues = useCallback(
(
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
values: (
prev: CanUpdateSequencePropsResponse,
) => CanUpdateSequencePropsResponse,
) => {
setCodeValuesMapState((prev) => {
- const key = nodePathToString(nodePath);
+ const key = makeSequencePropsSubscriptionKey(nodePath);
const prevKey = prev[key];
const newKey = values(prevKey);
@@ -319,14 +332,14 @@ export const SequenceManagerProvider: React.FC<{
}, [hidden]);
const getDragOverrides = useCallback(
- (nodePath: SequenceNodePath) => {
- return dragOverrides[nodePathToString(nodePath)] ?? {};
+ (nodePath: SequencePropsSubscriptionKey) => {
+ return dragOverrides[makeSequencePropsSubscriptionKey(nodePath)] ?? {};
},
[dragOverrides],
);
const getEffectDragOverrides = useCallback(
- (nodePath: SequenceNodePath, effectIndex: number) => {
+ (nodePath: SequencePropsSubscriptionKey, effectIndex: number) => {
return (
effectDragOverridesState[
effectDragOverridesKey(nodePath, effectIndex)
@@ -337,14 +350,14 @@ export const SequenceManagerProvider: React.FC<{
);
const getCodeValues = useCallback(
- (nodePath: SequenceNodePath) => {
+ (nodePath: SequencePropsSubscriptionKey) => {
return getCodeValuesCtx(codeValues, nodePath);
},
[codeValues],
);
const getEffectCodeValues = useCallback(
- (nodePath: SequenceNodePath, effectIndex: number) => {
+ (nodePath: SequencePropsSubscriptionKey, effectIndex: number) => {
return getEffectCodeValuesCtx({codeValues, nodePath, effectIndex});
},
[codeValues],
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index eaf81454b9..026526ec52 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -125,6 +125,7 @@ import type {
CanUpdateSequencePropsResponseTrue,
CanUpdateSequencePropsResponseFalse,
SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from './SequenceManager.js';
import {
VisualModeCodeValuesContext,
@@ -382,6 +383,7 @@ export type {
OverrideIdsToNodePathsGettersContext,
OverrideIdsToNodePathsSettersContext,
SequenceNodePath,
+ SequencePropsSubscriptionKey,
OverrideIdToNodePaths,
OverrideToNodeSetters,
OverrideToNodePathGetters,
diff --git a/packages/core/src/sequence-node-path.tsx b/packages/core/src/sequence-node-path.tsx
index a0a41ab08d..1999d7a512 100644
--- a/packages/core/src/sequence-node-path.tsx
+++ b/packages/core/src/sequence-node-path.tsx
@@ -1,7 +1,10 @@
import {createContext} from 'react';
-import type {SequenceNodePath} from './SequenceManager';
+import type {SequencePropsSubscriptionKey} from './SequenceManager';
-export type OverrideIdToNodePaths = Record<string, SequenceNodePath>;
+export type OverrideIdToNodePaths = Record<
+ string,
+ SequencePropsSubscriptionKey
+>;
export type OverrideToNodePathGetters = {
overrideIdToNodePathMappings: OverrideIdToNodePaths;
@@ -10,7 +13,7 @@ export type OverrideToNodePathGetters = {
export type OverrideToNodeSetters = {
setOverrideIdToNodePath: (
overrideId: string,
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
) => void;
};
diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.ts
index a902b222f1..56c1d0b2fc 100644
--- a/packages/core/src/use-schema.ts
+++ b/packages/core/src/use-schema.ts
@@ -6,7 +6,7 @@ import type {
} from './sequence-field-schema.js';
import type {
CanUpdateSequencePropsResponse,
- SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from './SequenceManager.js';
export type CanUpdateSequencePropStatusTrue = {
@@ -28,20 +28,20 @@ export type EffectDragOverrides = Record<string, Record<string, unknown>>;
export type CodeValues = Record<string, CanUpdateSequencePropsResponse>;
export type GetCodeValues = (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
) => Record<string, CanUpdateSequencePropStatus> | undefined;
export type GetEffectCodeValues = (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
) => Record<string, CanUpdateSequencePropStatus> | undefined;
export type GetDragOverrides = (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
) => DragOverrides[string];
export type GetEffectDragOverrides = (
- nodePath: SequenceNodePath,
+ nodePath: SequencePropsSubscriptionKey,
effectIndex: number,
) => Record<string, unknown>;
diff --git a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
index a9a50e577b..cd196dbd32 100644
--- a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
@@ -471,7 +471,12 @@ export const computeSequencePropsStatusFromFilenameByLine = ({
effects,
remotionRoot,
}),
- nodePath: resolvedNodePath,
+ nodePath: {
+ absolutePath,
+ nodePath: resolvedNodePath,
+ sequenceKeys: keys,
+ effectKeys: effects.map((effect) => getAllSchemaKeys(effect)),
+ },
success: true,
};
} catch (err) {
diff --git a/packages/studio-server/src/preview-server/routes/save-effect-props.ts b/packages/studio-server/src/preview-server/routes/save-effect-props.ts
index 4aa4d2010a..2907efd0a6 100644
--- a/packages/studio-server/src/preview-server/routes/save-effect-props.ts
+++ b/packages/studio-server/src/preview-server/routes/save-effect-props.ts
@@ -53,7 +53,7 @@ export const saveEffectPropsHandler: ApiHandler<
const {output, oldValueString, formatted, logLine} = await updateEffectProps({
input: fileContents,
- sequenceNodePath,
+ sequenceNodePath: sequenceNodePath.nodePath,
effectIndex,
update: {
key,
@@ -120,7 +120,7 @@ export const saveEffectPropsHandler: ApiHandler<
printUndoHint(logLevel);
const ast = parseAst(readFileSync(absolutePath, 'utf-8'));
- const jsx = findJsxElementAtNodePath(ast, sequenceNodePath);
+ const jsx = findJsxElementAtNodePath(ast, sequenceNodePath.nodePath);
if (!jsx) {
return {
canUpdate: false,
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 b970c60e6c..eee4f727c4 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
@@ -43,7 +43,7 @@ export const saveSequencePropsHandler: ApiHandler<
const {output, oldValueStrings, formatted, logLine, removedProps} =
await updateSequenceProps({
input: fileContents,
- nodePath,
+ nodePath: nodePath.nodePath,
updates: [
{
key,
@@ -117,7 +117,7 @@ export const saveSequencePropsHandler: ApiHandler<
const newStatus = computeSequencePropsOnlyStatus({
fileName,
keys: getAllSchemaKeys(schema),
- nodePath,
+ nodePath: nodePath.nodePath,
remotionRoot,
});
diff --git a/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts b/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
index 77e18e5b17..2bacfd65f0 100644
--- a/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
@@ -11,7 +11,7 @@ export const unsubscribeFromSequenceProps: ApiHandler<
}) => {
unsubscribeFromSequencePropsWatchers({
fileName,
- nodePath,
+ nodePath: nodePath.nodePath,
remotionRoot,
clientId,
sequenceKeys,
diff --git a/packages/studio-server/src/preview-server/sequence-props-watchers.ts b/packages/studio-server/src/preview-server/sequence-props-watchers.ts
index e14e21d6de..717ea37621 100644
--- a/packages/studio-server/src/preview-server/sequence-props-watchers.ts
+++ b/packages/studio-server/src/preview-server/sequence-props-watchers.ts
@@ -1,6 +1,7 @@
import path from 'node:path';
import {
getAllSchemaKeys,
+ stringifySequenceSubscriptionKey,
type SubscribeToSequencePropsResponse,
} from '@remotion/studio-shared';
import type {
@@ -24,20 +25,6 @@ type WatcherInfo = {
const sequencePropsWatchers: Record<string, Record<string, WatcherInfo>> = {};
-const makeWatcherKey = ({
- absolutePath,
- nodePath,
- sequenceKeys,
- effectKeys,
-}: {
- absolutePath: string;
- nodePath: SequenceNodePath;
- sequenceKeys: string[];
- effectKeys: string[][];
-}): string => {
- return `${absolutePath}:${JSON.stringify(nodePath)}:${sequenceKeys.join('\0')}:${effectKeys.map((keys) => keys.join('\0')).join('\0\0')}`;
-};
-
const getSequencePropsStatus = ({
fileName,
line,
@@ -66,7 +53,16 @@ const getSequencePropsStatus = ({
});
if (cachedResult.canUpdate) {
- return {status: cachedResult, nodePath: cachedNodePath, success: true};
+ return {
+ status: cachedResult,
+ nodePath: {
+ absolutePath: fileName,
+ nodePath: cachedNodePath,
+ sequenceKeys: keys,
+ effectKeys: effects.map((effect) => getAllSchemaKeys(effect)),
+ },
+ success: true,
+ };
}
}
@@ -114,15 +110,10 @@ export const subscribeToSequencePropsWatchers = ({
const absolutePath = path.resolve(remotionRoot, fileName);
// Cache the resolved nodePath for future lookups with stale source maps
- setCachedNodePath(fileName, line, column, initialResult.nodePath);
+ setCachedNodePath(fileName, line, column, initialResult.nodePath.nodePath);
const {nodePath} = initialResult;
- const watcherKey = makeWatcherKey({
- absolutePath,
- nodePath,
- sequenceKeys: keys,
- effectKeys: effects.map((effect) => getAllSchemaKeys(effect)),
- });
+ const watcherKey = stringifySequenceSubscriptionKey(nodePath);
// If a watcher already exists for this key, just bump the ref count
if (sequencePropsWatchers[clientId]?.[watcherKey]) {
@@ -142,7 +133,7 @@ export const subscribeToSequencePropsWatchers = ({
try {
result = computeSequencePropsStatusFromContent({
fileContents: event.content,
- nodePath,
+ nodePath: nodePath.nodePath,
keys,
effects,
});
@@ -186,7 +177,7 @@ export const unsubscribeFromSequencePropsWatchers = ({
effectKeys: string[][];
}) => {
const absolutePath = path.resolve(remotionRoot, fileName);
- const watcherKey = makeWatcherKey({
+ const watcherKey = stringifySequenceSubscriptionKey({
absolutePath,
nodePath,
sequenceKeys,
diff --git a/packages/studio-server/src/test/discriminated-union-update.test.ts b/packages/studio-server/src/test/discriminated-union-update.test.ts
index 29a915f3e6..aaeee7a059 100644
--- a/packages/studio-server/src/test/discriminated-union-update.test.ts
+++ b/packages/studio-server/src/test/discriminated-union-update.test.ts
@@ -15,7 +15,12 @@ test('Should correctly separate discriminated union for layout', () => {
currentRuntimeValueDotNotation: {
layout: 'none',
},
- nodePath: [],
+ nodePath: {
+ absolutePath: '',
+ nodePath: [],
+ sequenceKeys: [],
+ effectKeys: [],
+ },
getCodeValues: () => undefined,
getDragOverrides: () => ({}),
});
@@ -28,7 +33,12 @@ test('Should expose absolute-fill variant fields when active', () => {
currentRuntimeValueDotNotation: {
layout: 'absolute-fill',
},
- nodePath: [],
+ nodePath: {
+ absolutePath: '',
+ nodePath: [],
+ sequenceKeys: [],
+ effectKeys: [],
+ },
getCodeValues: () => undefined,
getDragOverrides: () => ({}),
});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index fea5025ed6..54b8f62aed 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -17,8 +17,9 @@ import type {
CanUpdateSequencePropsResponseTrue,
CanUpdateSequencePropStatus,
SequenceSchema,
+ SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from 'remotion';
-import type {SequenceNodePath} from 'remotion';
import type {RecastCodemod, VisualControlChange} from './codemods';
import type {PackageManager} from './package-manager';
import type {ProjectInfo} from './project-info';
@@ -211,7 +212,7 @@ export type UnsubscribeFromDefaultPropsRequest = {
export type CanUpdateSequencePropsRequest = {
fileName: string;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
keys: string[];
};
@@ -228,7 +229,7 @@ export type SubscribeToSequencePropsResponse =
| {
success: true;
status: CanUpdateSequencePropsResponseTrue;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
}
| {
success: false;
@@ -237,7 +238,7 @@ export type SubscribeToSequencePropsResponse =
export type UnsubscribeFromSequencePropsRequest = {
fileName: string;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
clientId: string;
sequenceKeys: string[];
effectKeys: string[][];
@@ -245,7 +246,7 @@ export type UnsubscribeFromSequencePropsRequest = {
export type SaveSequencePropsRequest = {
fileName: string;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
key: string;
value: string;
defaultValue: string | null;
@@ -264,7 +265,7 @@ export type SaveSequencePropsResponse =
export type SaveEffectPropsRequest = {
fileName: string;
- sequenceNodePath: SequenceNodePath;
+ sequenceNodePath: SequencePropsSubscriptionKey;
effectIndex: number;
key: string;
value: string;
diff --git a/packages/studio-shared/src/event-source-event.ts b/packages/studio-shared/src/event-source-event.ts
index 08a42497d4..b72bb82977 100644
--- a/packages/studio-shared/src/event-source-event.ts
+++ b/packages/studio-shared/src/event-source-event.ts
@@ -1,5 +1,8 @@
import type {StaticFile} from 'remotion';
-import type {SequenceNodePath, CanUpdateSequencePropsResponse} from 'remotion';
+import type {
+ CanUpdateSequencePropsResponse,
+ SequencePropsSubscriptionKey,
+} from 'remotion';
import type {CanUpdateDefaultPropsResponse} from './api-requests';
import type {HotMiddlewareMessage} from './hot-middleware';
import type {CompletedClientRender, RenderJob} from './render-job';
@@ -51,7 +54,7 @@ export type EventSourceEvent =
| {
type: 'sequence-props-updated';
fileName: string;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
result: CanUpdateSequencePropsResponse;
}
| {
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 4a39dae04e..e76ee45eea 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -121,3 +121,4 @@ export {EnumPath, stringifyDefaultProps} from './stringify-default-props';
export type {VisualControlChange} from './codemods';
export {optimisticUpdateForCodeValues} from './optimistic-update-for-code-values';
export {optimisticUpdateForEffectCodeValues} from './optimistic-update-for-effect-code-values';
+export {stringifySequenceSubscriptionKey} from './stringify-sequence-subscription-key';
diff --git a/packages/studio-shared/src/schema-field-info.ts b/packages/studio-shared/src/schema-field-info.ts
index b0539aa181..f8870d9b23 100644
--- a/packages/studio-shared/src/schema-field-info.ts
+++ b/packages/studio-shared/src/schema-field-info.ts
@@ -6,7 +6,7 @@ import type {
SequenceSchema,
GetDragOverrides,
GetCodeValues,
- SequenceNodePath,
+ SequencePropsSubscriptionKey,
EffectDefinition,
} from 'remotion';
import {Internals} from 'remotion';
@@ -60,7 +60,7 @@ export const getFieldsToShow = ({
currentRuntimeValueDotNotation: Record<string, unknown>;
getDragOverrides: GetDragOverrides;
getCodeValues: GetCodeValues;
- nodePath: SequenceNodePath;
+ nodePath: SequencePropsSubscriptionKey;
}): SequenceSchemaFieldInfo[] | null => {
const {merged: valuesDotNotation} =
Internals.computeEffectiveSchemaValuesDotNotation({
diff --git a/packages/studio-shared/src/stringify-sequence-subscription-key.ts b/packages/studio-shared/src/stringify-sequence-subscription-key.ts
new file mode 100644
index 0000000000..45b5b8d8f5
--- /dev/null
+++ b/packages/studio-shared/src/stringify-sequence-subscription-key.ts
@@ -0,0 +1,7 @@
+import type {SequencePropsSubscriptionKey} from 'remotion';
+
+export const stringifySequenceSubscriptionKey = (
+ key: SequencePropsSubscriptionKey,
+): string => {
+ return `${key.absolutePath}:${JSON.stringify(key.nodePath)}:${key.sequenceKeys.join('\0')}:${key.effectKeys.map((keys) => keys.join('\0')).join('\0\0')}`;
+};
diff --git a/packages/studio/src/components/ExpandedTracksProvider.tsx b/packages/studio/src/components/ExpandedTracksProvider.tsx
index 1763945de0..f0d732b6c1 100644
--- a/packages/studio/src/components/ExpandedTracksProvider.tsx
+++ b/packages/studio/src/components/ExpandedTracksProvider.tsx
@@ -1,8 +1,13 @@
+import {stringifySequenceSubscriptionKey} from '@remotion/studio-shared';
import React, {createContext, useCallback, useMemo, useState} from 'react';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
const nodePathInfoToKey = (info: SequenceNodePathInfo): string =>
- JSON.stringify([info.nodePath, info.index]);
+ [
+ stringifySequenceSubscriptionKey(info.sequenceSubscriptionKey),
+ info.auxiliaryKeys.join('.'),
+ info.index,
+ ].join('.');
const LOCAL_STORAGE_KEY = 'remotion.editor.expandedTracks';
diff --git a/packages/studio/src/components/SequencePropsSubscriptionProvider.tsx b/packages/studio/src/components/SequencePropsSubscriptionProvider.tsx
index 9b0e7281c5..15a2a2627b 100644
--- a/packages/studio/src/components/SequencePropsSubscriptionProvider.tsx
+++ b/packages/studio/src/components/SequencePropsSubscriptionProvider.tsx
@@ -4,7 +4,7 @@ import type {
OverrideIdToNodePaths,
OverrideToNodePathGetters,
OverrideToNodeSetters,
- SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from 'remotion';
export const SequencePropsSubscriptionProvider: React.FC<{
@@ -14,7 +14,7 @@ export const SequencePropsSubscriptionProvider: React.FC<{
useState<OverrideIdToNodePaths>({});
const setOverrideIdToNodePath = useCallback(
- (overrideId: string, state: SequenceNodePath) => {
+ (overrideId: string, state: SequencePropsSubscriptionKey) => {
setOverrideIdToNodePathMap((prev) => {
const existing = prev[overrideId];
if (existing && existing === state) {
diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
index d416e297eb..0a0a8668e7 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
@@ -3,7 +3,7 @@ import React, {useCallback, useContext, useMemo} from 'react';
import type {
CanUpdateEffectPropsResponse,
CanUpdateSequencePropsResponse,
- SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from 'remotion';
import {Internals} from 'remotion';
import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';
@@ -39,7 +39,7 @@ const fieldLabelRow: React.CSSProperties = {
const Value: React.FC<{
readonly field: EffectSchemaFieldInfo;
- readonly nodePath: SequenceNodePath;
+ readonly nodePath: SequencePropsSubscriptionKey;
readonly validatedLocation: CodePosition | null;
}> = ({field, nodePath, validatedLocation}) => {
const {setEffectDragOverrides, clearEffectDragOverrides, setCodeValues} =
@@ -205,7 +205,7 @@ export const TimelineEffectFieldRow: React.FC<{
readonly validatedLocation: CodePosition | null;
readonly paddingLeft: number;
readonly nestedDepth: number;
- readonly nodePath: SequenceNodePath;
+ readonly nodePath: SequencePropsSubscriptionKey;
}> = ({field, validatedLocation, paddingLeft, nestedDepth, nodePath}) => {
const style = useMemo(() => {
return {
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
index 34255f68bc..b493d69579 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx
@@ -1,5 +1,5 @@
import React, {useMemo} from 'react';
-import type {SequenceSchema, SequenceNodePath} from 'remotion';
+import type {SequenceSchema, SequencePropsSubscriptionKey} from 'remotion';
import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
import type {TimelineTreeNode} from '../../helpers/timeline-layout';
@@ -42,7 +42,7 @@ export const TimelineExpandedRow: React.FC<{
readonly getIsExpanded: GetIsExpanded;
readonly toggleTrack: (nodePathInfo: SequenceNodePathInfo) => void;
readonly validatedLocation: CodePosition | null;
- readonly nodePath: SequenceNodePath;
+ readonly nodePath: SequencePropsSubscriptionKey;
readonly schema: SequenceSchema;
}> = ({
node,
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index c5e3e59e58..4837d5af5f 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -113,7 +113,7 @@ export const TimelineExpandedSection: React.FC<{
getIsExpanded={getIsExpanded}
toggleTrack={toggleTrack}
validatedLocation={validatedLocation}
- nodePath={nodePathInfo.nodePath}
+ nodePath={nodePathInfo.sequenceSubscriptionKey}
schema={schema}
/>
</React.Fragment>
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index a9cd70bc30..f2c607abef 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -3,7 +3,7 @@ import React, {useCallback, useContext, useMemo} from 'react';
import type {
CanUpdateSequencePropStatusTrue,
CanUpdateSequencePropsResponse,
- SequenceNodePath,
+ SequencePropsSubscriptionKey,
} from 'remotion';
import type {SequenceSchema} from 'remotion';
import {Internals} from 'remotion';
@@ -44,7 +44,7 @@ const fieldLabelRow: React.CSSProperties = {
const Value: React.FC<{
readonly field: SchemaFieldInfo;
- readonly nodePath: SequenceNodePath;
+ readonly nodePath: SequencePropsSubscriptionKey;
readonly validatedLocation: CodePosition | null;
readonly schema: SequenceSchema;
readonly codeValue: CanUpdateSequencePropStatusTrue;
@@ -190,7 +190,7 @@ export const TimelineFieldRow: React.FC<{
readonly validatedLocation: CodePosition | null;
readonly paddingLeft: number;
readonly nestedDepth: number;
- readonly nodePath: SequenceNodePath;
+ readonly nodePath: SequencePropsSubscriptionKey;
readonly schema: SequenceSchema;
}> = ({
field,
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index d384f2f08f..788266d4f4 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -35,7 +35,7 @@ export const TimelineListItem: React.FC<{
readonly isCompact: boolean;
readonly nodePathInfo: SequenceNodePathInfo | null;
}> = ({nestedDepth, sequence, isCompact, nodePathInfo}) => {
- const nodePath = nodePathInfo?.nodePath ?? null;
+ const nodePath = nodePathInfo?.sequenceSubscriptionKey ?? null;
const {previewServerState} = useContext(StudioServerConnectionCtx);
const previewConnected = previewServerState.type === 'connected';
const {hidden, setHidden} = useContext(
@@ -90,7 +90,7 @@ export const TimelineListItem: React.FC<{
try {
const result = await callApi('/api/duplicate-jsx-node', {
fileName: validatedLocation.source,
- nodePath,
+ nodePath: nodePath.nodePath,
});
if (result.success) {
showNotification('Duplicated sequence in source file', 2000);
@@ -121,7 +121,7 @@ export const TimelineListItem: React.FC<{
try {
const result = await callApi('/api/delete-jsx-node', {
fileName: validatedLocation.source,
- nodePath,
+ nodePath: nodePath.nodePath,
});
if (result.success) {
showNotification('Removed sequence from source file', 2000);
diff --git a/packages/studio/src/helpers/calculate-timeline.ts b/packages/studio/src/helpers/calculate-timeline.ts
index cf045ef9c3..a21ab633f0 100644
--- a/packages/studio/src/helpers/calculate-timeline.ts
+++ b/packages/studio/src/helpers/calculate-timeline.ts
@@ -1,3 +1,4 @@
+import {stringifySequenceSubscriptionKey} from '@remotion/studio-shared';
import type {LoopDisplay, OverrideIdToNodePaths, TSequence} from 'remotion';
import {
getCascadedStart,
@@ -97,7 +98,12 @@ export const calculateTimeline = ({
cascadedStart,
cascadedDuration: sequence.duration,
nodePathInfo: nodePath
- ? {nodePath, index: 0, numberOfSequencesWithThisNodePath: 0}
+ ? {
+ sequenceSubscriptionKey: nodePath,
+ auxiliaryKeys: [],
+ index: 0,
+ numberOfSequencesWithThisNodePath: 0,
+ }
: null,
});
}
@@ -139,13 +145,16 @@ export const calculateTimeline = ({
return track;
}
- const key = track.nodePathInfo.nodePath.join('.');
+ const key = stringifySequenceSubscriptionKey(
+ track.nodePathInfo.sequenceSubscriptionKey,
+ );
const index = nodePathIndexCounters.get(key) ?? 0;
nodePathIndexCounters.set(key, index + 1);
return {
...track,
nodePathInfo: {
- nodePath: track.nodePathInfo.nodePath,
+ sequenceSubscriptionKey: track.nodePathInfo.sequenceSubscriptionKey,
+ auxiliaryKeys: track.nodePathInfo.auxiliaryKeys,
index,
numberOfSequencesWithThisNodePath: 0,
},
@@ -156,12 +165,15 @@ export const calculateTimeline = ({
return track;
}
- const key = track.nodePathInfo.nodePath.join('.');
+ const key = stringifySequenceSubscriptionKey(
+ track.nodePathInfo.sequenceSubscriptionKey,
+ );
return {
...track,
nodePathInfo: {
- nodePath: track.nodePathInfo.nodePath,
+ sequenceSubscriptionKey: track.nodePathInfo.sequenceSubscriptionKey,
+ auxiliaryKeys: track.nodePathInfo.auxiliaryKeys,
index: track.nodePathInfo.index,
numberOfSequencesWithThisNodePath:
nodePathIndexCounters.get(key) ?? 0,
diff --git a/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts b/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
index a22af0e468..74e8bbdd67 100644
--- a/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
+++ b/packages/studio/src/helpers/get-timeline-sequence-sort-key.ts
@@ -1,7 +1,8 @@
-import type {SequenceNodePath, TSequence} from 'remotion';
+import type {SequencePropsSubscriptionKey, TSequence} from 'remotion';
export type SequenceNodePathInfo = {
- nodePath: SequenceNodePath;
+ sequenceSubscriptionKey: SequencePropsSubscriptionKey;
+ auxiliaryKeys: string[];
index: number;
numberOfSequencesWithThisNodePath: number;
};
diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.ts
index ed0a97a311..bbcdae859e 100644
--- a/packages/studio/src/helpers/timeline-layout.ts
+++ b/packages/studio/src/helpers/timeline-layout.ts
@@ -67,24 +67,25 @@ export const buildTimelineTree = ({
getCodeValues: GetCodeValues;
}): TimelineTreeNode[] => {
const roots: TimelineTreeNode[] = [];
- const {nodePath, index} = nodePathInfo;
+ const {sequenceSubscriptionKey, index, auxiliaryKeys} = nodePathInfo;
if (sequence.effects.length > 0) {
roots.push({
kind: 'group',
nodePathInfo: {
- nodePath: [...nodePath, 'effects'],
+ sequenceSubscriptionKey,
+ auxiliaryKeys: [...auxiliaryKeys, 'effects'],
index,
numberOfSequencesWithThisNodePath: 0,
},
label: 'Effects',
children: sequence.effects.map((effect, i): TimelineTreeNode => {
- const effectNodePath = [...nodePath, 'effects', i];
const effectFields = getEffectFieldsToShow(effect, i);
return {
kind: 'group',
nodePathInfo: {
- nodePath: effectNodePath,
+ sequenceSubscriptionKey,
+ auxiliaryKeys: [...auxiliaryKeys, 'effects', i.toString()],
index,
numberOfSequencesWithThisNodePath: 0,
},
@@ -93,7 +94,8 @@ export const buildTimelineTree = ({
(f): TimelineTreeNode => ({
kind: 'field',
nodePathInfo: {
- nodePath: [...effectNodePath, f.key],
+ sequenceSubscriptionKey,
+ auxiliaryKeys: [...auxiliaryKeys, f.key],
index,
numberOfSequencesWithThisNodePath: 0,
},
@@ -112,7 +114,7 @@ export const buildTimelineTree = ({
sequence.controls!.currentRuntimeValueDotNotation,
getDragOverrides,
getCodeValues,
- nodePath,
+ nodePath: sequenceSubscriptionKey,
});
if (controlFields && controlFields.length > 0) {
@@ -120,7 +122,8 @@ export const buildTimelineTree = ({
roots.push({
kind: 'field',
nodePathInfo: {
- nodePath: [...nodePath, 'controls', f.key],
+ sequenceSubscriptionKey,
+ auxiliaryKeys: [...auxiliaryKeys, 'controls', f.key],
index,
numberOfSequencesWithThisNodePath: 0,
},