Skip to content

πŸŽ₯ Make videos programmatically with React

fields to show

Jonny Burger229cdad22c38
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index 4bf45596d9..23a4430e4e 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -97,7 +97,7 @@ export type LoopDisplay = {
export type SequenceControls = {
schema: SequenceSchema;
- currentValue: Record<string, unknown>;
+ currentRuntimeValueDotNotation: Record<string, unknown>;
overrideId: string;
};
diff --git a/packages/core/src/flatten-schema.ts b/packages/core/src/flatten-schema.ts
index 1248832364..a031d6ece7 100644
--- a/packages/core/src/flatten-schema.ts
+++ b/packages/core/src/flatten-schema.ts
@@ -23,3 +23,35 @@ export const flattenActiveSchema = (
return out;
};
+
+export const getFlatSchemaWithAllKeys = (
+ schema: SequenceSchema,
+): SequenceSchema => {
+ const out: SequenceSchema = {};
+
+ const addKey = (key: string, field: SequenceSchema[string]) => {
+ if (key in out) {
+ throw new Error(
+ `Duplicate key "${key}" in schema: discriminated union variants must not share keys`,
+ );
+ }
+
+ out[key] = field;
+ };
+
+ for (const key of Object.keys(schema)) {
+ const field = schema[key];
+ addKey(key, field);
+
+ if (field.type === 'enum') {
+ for (const variant of Object.values(field.variants)) {
+ const flatVariant = getFlatSchemaWithAllKeys(variant);
+ for (const variantKey of Object.keys(flatVariant)) {
+ addKey(variantKey, flatVariant[variantKey]);
+ }
+ }
+ }
+ }
+
+ return out;
+};
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 7770c18a95..3aabee194c 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -53,6 +53,10 @@ import {
addSequenceStackTraces,
getComponentsToAddStacksTo,
} from './enable-sequence-stack-traces.js';
+import {
+ flattenActiveSchema,
+ getFlatSchemaWithAllKeys,
+} from './flatten-schema.js';
import {getEffectiveVisualModeValue} from './get-effective-visual-mode-value.js';
import {
getPreviewDomElement,
@@ -205,6 +209,8 @@ export const Internals = {
wrapInSchema,
sequenceSchema,
sequenceStyleSchema,
+ flattenActiveSchema,
+ getFlatSchema: getFlatSchemaWithAllKeys,
useSequenceControlOverride,
RemotionRootContexts,
CompositionManagerProvider,
diff --git a/packages/core/src/test/wrap-in-schema-helpers.test.ts b/packages/core/src/test/wrap-in-schema-helpers.test.ts
new file mode 100644
index 0000000000..66414b1533
--- /dev/null
+++ b/packages/core/src/test/wrap-in-schema-helpers.test.ts
@@ -0,0 +1,91 @@
+import {expect, test} from 'bun:test';
+import {getFlatSchemaWithAllKeys} from '../flatten-schema.js';
+import {sequenceSchema} from '../sequence-field-schema.js';
+import {
+ getNestedValue,
+ mergeValues,
+ readValuesFromProps,
+ selectActiveKeys,
+} from '../wrap-in-schema.js';
+
+test('getFlatSchema(sequenceSchema) exposes every variant key', () => {
+ const flat = getFlatSchemaWithAllKeys(sequenceSchema);
+ expect(Object.keys(flat).sort()).toEqual(
+ [
+ 'layout',
+ 'style.translate',
+ 'style.scale',
+ 'style.rotate',
+ 'style.opacity',
+ ].sort(),
+ );
+});
+
+test('readValuesFromProps reads dot-notation keys via getNestedValue', () => {
+ const props = {
+ layout: 'absolute-fill',
+ style: {scale: 1.74, opacity: 0.5},
+ };
+ const flatKeys = Object.keys(getFlatSchemaWithAllKeys(sequenceSchema));
+ const values = readValuesFromProps(props, flatKeys);
+ expect(values.layout).toBe('absolute-fill');
+ expect(values['style.scale']).toBe(1.74);
+ expect(values['style.opacity']).toBe(0.5);
+ expect(values['style.rotate']).toBeUndefined();
+});
+
+test('selectActiveKeys returns only the layout key when layout=none', () => {
+ const values = {
+ layout: 'none',
+ 'style.scale': 2,
+ };
+ expect(selectActiveKeys(sequenceSchema, values)).toEqual(['layout']);
+});
+
+test('selectActiveKeys exposes style.* keys when layout=absolute-fill', () => {
+ const values = {
+ layout: 'absolute-fill',
+ 'style.scale': 2,
+ };
+ expect(selectActiveKeys(sequenceSchema, values).sort()).toEqual(
+ [
+ 'layout',
+ 'style.translate',
+ 'style.scale',
+ 'style.rotate',
+ 'style.opacity',
+ ].sort(),
+ );
+});
+
+test('mergeValues writes nested values back into props with dot keys', () => {
+ const props = {layout: 'absolute-fill', style: {scale: 1}};
+ const values = {layout: 'absolute-fill', 'style.scale': 2};
+ const merged = mergeValues({
+ props,
+ valuesDotNotation: values,
+ schemaKeys: ['layout', 'style.scale'],
+ });
+ expect(merged.layout).toBe('absolute-fill');
+ expect((merged.style as {scale: number}).scale).toBe(2);
+});
+
+test('end-to-end: layout=none drops style.scale from active props', () => {
+ const props = {layout: 'none', style: {scale: 2}};
+ const flatKeys = Object.keys(getFlatSchemaWithAllKeys(sequenceSchema));
+ const values = readValuesFromProps(props, flatKeys);
+ const activeKeys = selectActiveKeys(sequenceSchema, values);
+ const merged = mergeValues({
+ props,
+ valuesDotNotation: values,
+ schemaKeys: activeKeys,
+ });
+ expect(activeKeys).toEqual(['layout']);
+ // style.scale was not in activeKeys β†’ original style preserved, not overwritten
+ expect((merged.style as {scale: number}).scale).toBe(2);
+});
+
+test('getNestedValue returns undefined for missing nested keys', () => {
+ expect(getNestedValue({a: {}}, 'a.b.c')).toBeUndefined();
+ expect(getNestedValue({a: {b: 1}}, 'a.b')).toBe(1);
+});
diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.ts
index 76f9e0ccf6..0bd7f26501 100644
--- a/packages/core/src/use-schema.ts
+++ b/packages/core/src/use-schema.ts
@@ -1,9 +1,9 @@
/* eslint-disable react-hooks/rules-of-hooks */
-import {useContext, useMemo, useState} from 'react';
+import {useContext, useMemo} from 'react';
import type {SequenceControls} from './CompositionManager.js';
import {getEffectiveVisualModeValue} from './get-effective-visual-mode-value.js';
import type {
- SchemaKeysRecord,
+ SequenceFieldSchema,
SequenceSchema,
} from './sequence-field-schema.js';
import {VisualModeOverridesContext} from './SequenceManager.js';
@@ -13,36 +13,80 @@ export type CanUpdateSequencePropStatus =
| {canUpdate: true; codeValue: unknown}
| {canUpdate: false; reason: 'computed'};
-export const useSchema = <
- S extends SequenceSchema,
- T extends SchemaKeysRecord<S>,
->(
- schema: S | null,
- currentValue: (T & Record<Exclude<keyof T, keyof S>, never>) | null,
- externalOverrideId?: string,
+const findFieldInSchema = (
+ schema: SequenceSchema,
+ key: string,
+): SequenceFieldSchema | undefined => {
+ if (key in schema) {
+ return schema[key];
+ }
+
+ for (const field of Object.values(schema)) {
+ if (field.type !== 'enum') {
+ continue;
+ }
+
+ for (const variant of Object.values(field.variants)) {
+ const found = findFieldInSchema(variant, key);
+ if (found) {
+ return found;
+ }
+ }
+ }
+
+ return undefined;
+};
+
+const computeMergedValues = ({
+ schema,
+ currentValue,
+ overrideValues,
+ propStatus,
+}: {
+ schema: SequenceSchema;
+ currentValue: Record<string, unknown>;
+ overrideValues: Record<string, unknown>;
+ propStatus: Record<string, CanUpdateSequencePropStatus> | undefined;
+}): Record<string, unknown> => {
+ const merged: Record<string, unknown> = {};
+ for (const key of Object.keys(currentValue)) {
+ const codeValueStatus = propStatus?.[key] ?? null;
+ merged[key] = getEffectiveVisualModeValue({
+ codeValue: codeValueStatus,
+ runtimeValue: currentValue[key],
+ dragOverrideValue: overrideValues[key],
+ defaultValue: findFieldInSchema(schema, key)?.default,
+ shouldResortToDefaultValueIfUndefined: false,
+ });
+ }
+
+ return merged;
+};
+
+export const useSchema = <T extends Record<string, unknown>>(
+ schema: SequenceSchema | null,
+ currentRuntimeValueDotNotation: T | null,
+ overrideId: string,
): {
controls: SequenceControls | undefined;
- values: T;
+ valuesDotNotation: T;
} => {
const env = useRemotionEnvironment();
const earlyReturn = useMemo(() => {
if (!env.isStudio || env.isReadOnlyStudio) {
return {
controls: undefined,
- values: (currentValue ?? {}) as T,
+ valuesDotNotation: (currentRuntimeValueDotNotation ?? {}) as T,
};
}
return undefined;
- }, [env.isStudio, env.isReadOnlyStudio, currentValue]);
+ }, [env.isStudio, env.isReadOnlyStudio, currentRuntimeValueDotNotation]);
if (earlyReturn) {
return earlyReturn;
}
- // Intentional conditional hook call, useRemotionEnvironment is stable.
- const [generatedOverrideId] = useState(() => String(Math.random()));
- const overrideId = externalOverrideId ?? generatedOverrideId;
const {
visualModeEnabled,
dragOverrides: overrides,
@@ -54,63 +98,46 @@ export const useSchema = <
return undefined;
}
- if (schema === null || currentValue === null) {
+ if (schema === null || currentRuntimeValueDotNotation === null) {
return undefined;
}
return {
schema,
- currentValue,
+ currentRuntimeValueDotNotation,
overrideId,
};
- }, [schema, currentValue, overrideId, visualModeEnabled]);
+ }, [schema, currentRuntimeValueDotNotation, overrideId, visualModeEnabled]);
return useMemo(() => {
if (
controls === undefined ||
- currentValue === null ||
- schema === null ||
- !visualModeEnabled
+ currentRuntimeValueDotNotation === null ||
+ schema === null
) {
return {
controls: undefined,
- values: (currentValue ?? {}) as T,
+ valuesDotNotation: (currentRuntimeValueDotNotation ?? {}) as T,
};
}
- const overrideValues = overrides[overrideId] ?? {};
- const propStatus = codeValues[overrideId];
-
- const currentValueKeys = Object.keys(currentValue);
-
- const keysToUpdate = [...new Set(currentValueKeys)];
-
- const merged = {} as Record<string, unknown>;
-
- // Apply code values over runtime values, falling back to schema default
- for (const key of keysToUpdate) {
- const codeValueStatus = propStatus?.[key] ?? null;
-
- merged[key] = getEffectiveVisualModeValue({
- codeValue: codeValueStatus,
- runtimeValue: currentValue[key as keyof SchemaKeysRecord<S>] as unknown,
- dragOverrideValue: overrideValues[key],
- defaultValue: schema[key]?.default,
- shouldResortToDefaultValueIfUndefined: false,
- });
- }
+ const merged = computeMergedValues({
+ schema,
+ currentValue: currentRuntimeValueDotNotation,
+ overrideValues: overrides[overrideId] ?? {},
+ propStatus: codeValues[overrideId],
+ });
return {
controls,
- values: merged as T,
+ valuesDotNotation: merged as T,
};
}, [
controls,
- currentValue,
+ currentRuntimeValueDotNotation,
overrideId,
overrides,
codeValues,
schema,
- visualModeEnabled,
]);
};
diff --git a/packages/core/src/wrap-in-schema.ts b/packages/core/src/wrap-in-schema.ts
index 399a69010c..aef94706a7 100644
--- a/packages/core/src/wrap-in-schema.ts
+++ b/packages/core/src/wrap-in-schema.ts
@@ -1,15 +1,17 @@
-import React, {forwardRef, useContext, useState} from 'react';
+import React, {forwardRef, useState} from 'react';
import type {SequenceControls} from './CompositionManager.js';
-import {flattenActiveSchema, type ResolveValue} from './flatten-schema.js';
-import type {
- SchemaKeysRecord,
- SequenceSchema,
-} from './sequence-field-schema.js';
-import {VisualModeOverridesContext} from './SequenceManager.js';
+import {
+ flattenActiveSchema,
+ getFlatSchemaWithAllKeys,
+} from './flatten-schema.js';
+import type {SequenceSchema} from './sequence-field-schema.js';
import {useRemotionEnvironment} from './use-remotion-environment.js';
import {useSchema} from './use-schema.js';
-const getNestedValue = (obj: Record<string, unknown>, key: string): unknown => {
+export const getNestedValue = (
+ obj: Record<string, unknown>,
+ key: string,
+): unknown => {
const parts = key.split('.');
let current: unknown = obj;
for (const part of parts) {
@@ -25,15 +27,38 @@ const getNestedValue = (obj: Record<string, unknown>, key: string): unknown => {
return current;
};
-const mergeValues = (
+export const readValuesFromProps = (
props: Record<string, unknown>,
- values: Record<string, unknown>,
- schemaKeys: string[],
+ keys: string[],
): Record<string, unknown> => {
+ const out: Record<string, unknown> = {};
+ for (const key of keys) {
+ out[key] = getNestedValue(props, key);
+ }
+
+ return out;
+};
+
+export const selectActiveKeys = (
+ schema: SequenceSchema,
+ values: Record<string, unknown>,
+): string[] => {
+ return Object.keys(flattenActiveSchema(schema, (key) => values[key]));
+};
+
+export const mergeValues = ({
+ props,
+ valuesDotNotation,
+ schemaKeys,
+}: {
+ props: Record<string, unknown>;
+ valuesDotNotation: Record<string, unknown>;
+ schemaKeys: string[];
+}): Record<string, unknown> => {
const merged = {...props};
for (const key of schemaKeys) {
- const value = values[key];
+ const value = valuesDotNotation[key];
const parts = key.split('.');
if (parts.length === 1) {
@@ -87,49 +112,6 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
});
}
- // eslint-disable-next-line react-hooks/rules-of-hooks
- const [overrideId] = useState(() => String(Math.random()));
- // eslint-disable-next-line react-hooks/rules-of-hooks
- const {dragOverrides, codeValues} = useContext(VisualModeOverridesContext);
- const dragForThis = dragOverrides[overrideId] ?? {};
- const codeForThis = codeValues[overrideId];
-
- const propsRecord = props as Record<string, unknown>;
- const resolveDiscriminator: ResolveValue = (key) => {
- if (key in dragForThis) {
- return dragForThis[key];
- }
-
- const status = codeForThis?.[key];
- if (status && status.canUpdate) {
- return status.codeValue;
- }
-
- return getNestedValue(propsRecord, key);
- };
-
- const activeSchema = flattenActiveSchema(schema, resolveDiscriminator);
- const activeKeys = Object.keys(activeSchema);
-
- const schemaInput = {} as Record<string, unknown>;
- for (const key of activeKeys) {
- schemaInput[key] = getNestedValue(propsRecord, key);
- }
-
- // eslint-disable-next-line react-hooks/rules-of-hooks
- const {controls, values} = useSchema(
- activeSchema as S,
- schemaInput as SchemaKeysRecord<S> &
- Record<Exclude<keyof SchemaKeysRecord<S>, keyof S>, never>,
- overrideId,
- );
-
- const mergedProps = mergeValues(
- propsRecord,
- values as Record<string, unknown>,
- activeKeys,
- );
-
// If the parent has passed `_experimentalControls`, we should not override it.
// @ts-expect-error
if (props._experimentalControls) {
@@ -142,6 +124,37 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
});
}
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ const [overrideId] = useState(() => String(Math.random()));
+
+ // 1. Flatten the schema to get every possible key (across all variants).
+ const flatSchema = getFlatSchemaWithAllKeys(schema);
+ const flatKeys = Object.keys(flatSchema);
+
+ // 2. Read the runtime values for every flat key from the JSX props.
+ const currentRuntimeValueDotNotation = readValuesFromProps(
+ props as Record<string, unknown>,
+ flatKeys,
+ );
+
+ // 3. Apply drag/code overrides on top of the runtime values.
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ const {controls, valuesDotNotation} = useSchema(
+ schema,
+ currentRuntimeValueDotNotation,
+ overrideId,
+ );
+
+ // 4. Eliminate values forbidden by the resolved discriminated union.
+ const activeKeys = selectActiveKeys(schema, valuesDotNotation);
+
+ // 5. Apply the active values back onto the props.
+ const mergedProps = mergeValues({
+ props: props as Record<string, unknown>,
+ valuesDotNotation,
+ schemaKeys: activeKeys,
+ });
+
return React.createElement(Component, {
...mergedProps,
_experimentalControls: controls,
diff --git a/packages/studio-server/src/codemods/get-all-schema-keys.ts b/packages/studio-server/src/codemods/get-all-schema-keys.ts
new file mode 100644
index 0000000000..5090cb79f9
--- /dev/null
+++ b/packages/studio-server/src/codemods/get-all-schema-keys.ts
@@ -0,0 +1,6 @@
+import type {SequenceSchema} from 'remotion';
+import {Internals} from 'remotion';
+
+export const getAllSchemaKeys = (schema: SequenceSchema): string[] => {
+ return Object.keys(Internals.getFlatSchema(schema));
+};
diff --git a/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts b/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
index 5646d4361d..14639193a0 100644
--- a/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
@@ -2,18 +2,19 @@ import type {
SubscribeToSequencePropsRequest,
SubscribeToSequencePropsResponse,
} from '@remotion/studio-shared';
+import {getAllSchemaKeys} from '../../codemods/get-all-schema-keys';
import type {ApiHandler} from '../api-types';
import {subscribeToSequencePropsWatchers} from '../sequence-props-watchers';
export const subscribeToSequenceProps: ApiHandler<
SubscribeToSequencePropsRequest,
SubscribeToSequencePropsResponse
-> = ({input: {fileName, line, column, keys, clientId}, remotionRoot}) => {
+> = ({input: {fileName, line, column, schema, clientId}, remotionRoot}) => {
const result = subscribeToSequencePropsWatchers({
fileName,
line,
column,
- keys,
+ keys: getAllSchemaKeys(schema),
remotionRoot,
clientId,
});
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 7b68546d7f..cbca617b6b 100644
--- a/packages/studio-server/src/test/discriminated-union-update.test.ts
+++ b/packages/studio-server/src/test/discriminated-union-update.test.ts
@@ -2,16 +2,16 @@ import {expect, test} from 'bun:test';
import assert from 'node:assert';
import {readFileSync} from 'node:fs';
import path from 'node:path';
-import {getSchemaFields} from '@remotion/studio-shared';
+import {getFieldsToShow} from '@remotion/studio-shared';
import {Internals} from 'remotion';
import {parseAst} from '../codemods/parse-ast';
import {updateSequencePropsAst} from '../codemods/update-sequence-props';
import {lineColumnToNodePath} from '../preview-server/routes/can-update-sequence-props';
test('Should correctly separate discriminated union for layout', () => {
- const schemaFields = getSchemaFields({
+ const schemaFields = getFieldsToShow({
schema: Internals.sequenceSchema,
- currentValue: {
+ currentRuntimeValueDotNotation: {
layout: 'none',
},
overrideId: '0.7123890564498035',
@@ -19,6 +19,23 @@ test('Should correctly separate discriminated union for layout', () => {
expect(schemaFields?.map((s) => s.key)).toEqual(['layout']);
});
+test('Should expose absolute-fill variant fields when active', () => {
+ const schemaFields = getFieldsToShow({
+ schema: Internals.sequenceSchema,
+ currentRuntimeValueDotNotation: {
+ layout: 'absolute-fill',
+ },
+ overrideId: '0.5636826614884479',
+ });
+ expect(schemaFields?.map((s) => s.key)).toEqual([
+ 'layout',
+ 'style.translate',
+ 'style.scale',
+ 'style.rotate',
+ 'style.opacity',
+ ]);
+});
+
test('Should be able to update a discriminated union', () => {
const file = readFileSync(
path.join(__dirname, 'snapshots', 'discriminated-union.tsx'),
diff --git a/packages/studio-server/src/test/get-all-schema-keys.test.ts b/packages/studio-server/src/test/get-all-schema-keys.test.ts
new file mode 100644
index 0000000000..0ea0433590
--- /dev/null
+++ b/packages/studio-server/src/test/get-all-schema-keys.test.ts
@@ -0,0 +1,47 @@
+import {expect, test} from 'bun:test';
+import type {SequenceSchema} from 'remotion';
+import {Internals} from 'remotion';
+import {getAllSchemaKeys} from '../codemods/get-all-schema-keys';
+
+const {getFlatSchema} = Internals;
+
+test('getAllSchemaKeys returns every key across all enum variants', () => {
+ const keys = getAllSchemaKeys(Internals.sequenceSchema);
+ expect(keys.sort()).toEqual(
+ [
+ 'layout',
+ 'style.translate',
+ 'style.scale',
+ 'style.rotate',
+ 'style.opacity',
+ ].sort(),
+ );
+});
+
+test('getFlatSchema throws when discriminated union variants share a key', () => {
+ const conflictingSchema: SequenceSchema = {
+ mode: {
+ type: 'enum',
+ default: 'a',
+ description: 'Mode',
+ variants: {
+ a: {
+ shared: {
+ type: 'number',
+ default: 1,
+ },
+ },
+ b: {
+ shared: {
+ type: 'number',
+ default: 2,
+ },
+ },
+ },
+ },
+ };
+
+ expect(() => getFlatSchema(conflictingSchema)).toThrow(
+ 'Duplicate key "shared"',
+ );
+});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index 22d326a8c6..6c769ae701 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -214,7 +214,7 @@ export type SubscribeToSequencePropsRequest = {
fileName: string;
line: number;
column: number;
- keys: string[];
+ schema: SequenceSchema;
clientId: string;
};
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 8a7f2b204d..dccdb7bd33 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -98,7 +98,7 @@ export type {CompletedClientRender} from './render-job';
export {
SCHEMA_FIELD_ROW_HEIGHT,
UNSUPPORTED_FIELD_ROW_HEIGHT,
- getSchemaFields,
+ getFieldsToShow,
} from './schema-field-info';
export type {SchemaFieldInfo, SequenceControls} from './schema-field-info';
export {SOURCE_MAP_ENDPOINT} from './source-map-endpoint';
diff --git a/packages/studio-shared/src/schema-field-info.ts b/packages/studio-shared/src/schema-field-info.ts
index 7b6da271ae..8be10bab55 100644
--- a/packages/studio-shared/src/schema-field-info.ts
+++ b/packages/studio-shared/src/schema-field-info.ts
@@ -1,4 +1,5 @@
import type {SequenceControls, SequenceFieldSchema} from 'remotion';
+import {Internals} from 'remotion';
export type {SequenceControls};
@@ -8,7 +9,7 @@ export type SchemaFieldInfo = {
typeName: string;
supported: boolean;
rowHeight: number;
- currentValue: unknown;
+ currentRuntimeValue: unknown;
fieldSchema: SequenceFieldSchema;
};
@@ -23,14 +24,19 @@ const SUPPORTED_SCHEMA_TYPES = new Set([
'enum',
]);
-export const getSchemaFields = (
+export const getFieldsToShow = (
controls: SequenceControls | null,
): SchemaFieldInfo[] | null => {
if (!controls) {
return null;
}
- return Object.entries(controls.schema).map(([key, fieldSchema]) => {
+ const activeSchema = Internals.flattenActiveSchema(
+ controls.schema,
+ (key) => controls.currentRuntimeValueDotNotation[key],
+ );
+
+ return Object.entries(activeSchema).map(([key, fieldSchema]) => {
const typeName = fieldSchema.type;
const supported = SUPPORTED_SCHEMA_TYPES.has(typeName);
return {
@@ -41,7 +47,7 @@ export const getSchemaFields = (
rowHeight: supported
? SCHEMA_FIELD_ROW_HEIGHT
: UNSUPPORTED_FIELD_ROW_HEIGHT,
- currentValue: controls.currentValue[key],
+ currentRuntimeValue: controls.currentRuntimeValueDotNotation[key],
fieldSchema,
};
});
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index 1140c42349..4eb0917497 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -1,6 +1,6 @@
import type {SequenceNodePath} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
-import type {CanUpdateSequencePropStatus, SequenceSchema} from 'remotion';
+import type {SequenceSchema} from 'remotion';
import {Internals} from 'remotion';
import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';
import type {SchemaFieldInfo} from '../../helpers/timeline-layout';
@@ -63,7 +63,7 @@ export const TimelineFieldRow: React.FC<{
const effectiveValue = Internals.getEffectiveVisualModeValue({
codeValue: propStatus,
- runtimeValue: field.currentValue,
+ runtimeValue: field.currentRuntimeValue,
dragOverrideValue,
defaultValue: field.fieldSchema.default,
shouldResortToDefaultValueIfUndefined: true,
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 4cf585a506..a1672442dc 100644
--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
@@ -11,7 +11,6 @@ import {Internals, type CanUpdateSequencePropStatus} from 'remotion';
import type {TSequence} from 'remotion';
import type {OriginalPosition} from '../../error-overlay/react-overlay/utils/get-source-map';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
-import {getSchemaFields} from '../../helpers/timeline-layout';
import {callApi} from '../call-api';
export const useSequencePropsSubscription = (
@@ -41,16 +40,6 @@ export const useSequencePropsSubscription = (
);
const clientId = state.type === 'connected' ? state.clientId : undefined;
- const schemaFields = useMemo(
- () => getSchemaFields(sequence.controls),
- [sequence.controls],
- );
-
- const schemaKeysString = useMemo(
- () => (schemaFields ? schemaFields.map((f) => f.key).join(',') : null),
- [schemaFields],
- );
-
const validatedLocation = useMemo(() => {
if (
!originalLocation ||
@@ -111,21 +100,25 @@ export const useSequencePropsSubscription = (
!clientId ||
!locationSource ||
!locationLine ||
- locationColumn === null ||
- !schemaKeysString
+ locationColumn === null
) {
setPropStatusesForSequence(null);
updateSubscriptionState({nodePath: null, jsxInMapCallback: false});
return;
}
- const keys = schemaKeysString.split(',');
+ const schema = sequence.controls?.schema;
+ if (!schema) {
+ setPropStatusesForSequence(null);
+ updateSubscriptionState({nodePath: null, jsxInMapCallback: false});
+ return;
+ }
callApi('/api/subscribe-to-sequence-props', {
fileName: locationSource,
line: locationLine,
column: locationColumn,
- keys,
+ schema,
clientId,
})
.then((result) => {
@@ -174,14 +167,14 @@ export const useSequencePropsSubscription = (
}
};
}, [
- visualModeEnabled,
clientId,
- locationSource,
- locationLine,
locationColumn,
- schemaKeysString,
+ locationLine,
+ locationSource,
+ sequence.controls?.schema,
setPropStatusesForSequence,
updateSubscriptionState,
+ visualModeEnabled,
]);
useEffect(() => {