🎥 Make videos programmatically with React
Elements: Require exact dependency versions (#10093)
Igor Samokhovets65b335cdd462
diff --git a/.agents/skills/publish-element/SKILL.md b/.agents/skills/publish-element/SKILL.mdindex 22ebb37b45..a7ae6ca779 100644--- a/.agents/skills/publish-element/SKILL.md+++ b/.agents/skills/publish-element/SKILL.md@@ -26,7 +26,7 @@ bun run remotion## 2. Perform the publication review-Review the finished source, MDX page, and central definition against the Element Guidelines. Resolve placeholder content and finalize the description, display name, contributors, dimensions, duration, declared dependencies, preview padding, poster frame, and `preview` object. Confirm that `durationInFrames` is appropriate for both the preview and the `<Sequence>` installed into Studio, and that every external source import except `react`, `react-dom`, and `remotion` appears in `dependencies` with an exact version only when required. Confirm that `posterUrl` and `videoUrl` use flat `https://remotion.media/elements/<category>-<slug>-preview.png` and `.mp4` paths. Preview assets are composited onto the standard background and use MP4 for broad browser, social-card, and embed compatibility, even when the Element itself supports transparency. These explicit URLs are the publishing source of truth.+Review the finished source, MDX page, and central definition against the Element Guidelines. Resolve placeholder content and finalize the description, display name, contributors, dimensions, duration, declared dependencies, preview padding, poster frame, and `preview` object. Confirm that `durationInFrames` is appropriate for both the preview and the `<Sequence>` installed into Studio, and that every external source import except `react`, `react-dom`, and `remotion` appears in `dependencies`. Remotion packages must use `version: null`; every non-Remotion package must use an exact semantic version, not a range or tag. Confirm that `posterUrl` and `videoUrl` use flat `https://remotion.media/elements/<category>-<slug>-preview.png` and `.mp4` paths. Preview assets are composited onto the standard background and use MP4 for broad browser, social-card, and embed compatibility, even when the Element itself supports transparency. These explicit URLs are the publishing source of truth.Re-check the technical implementation requirements from the [`scaffold-element` skill](../scaffold-element/SKILL.md): The reusable implementation must remain in one self-contained TSX file, fill its configured bounds without a wrapper `<Sequence>` or preview-only source padding, and leave outer placement to the surrounding project. Animated entrances must have exits with inline, hardcoded frame ranges on useful named `Interactive.*` elements. Inner control names must not repeat the Element display name.diff --git a/.agents/skills/scaffold-element/SKILL.md b/.agents/skills/scaffold-element/SKILL.mdindex 14c8495f18..9e712d71dc 100644--- a/.agents/skills/scaffold-element/SKILL.md+++ b/.agents/skills/scaffold-element/SKILL.md@@ -16,7 +16,7 @@ Choose an existing category and a kebab-case slug. Before creating files, determ- Composition width, height, fps, and preview duration- Installed Element duration, or `null` when it should adapt to the composition- Fixed Element width and height, or `null` for both so it inherits the composition dimensions-- Every external source dependency as `{name, version}`, using `null` when no exact version is required+- Every external source dependency as `{name, version}`; use `null` for Remotion packages and an exact semantic version for every non-Remotion package- Preview padding, which affects only the docs preview and not the Element bounds- A provisional poster frame- Explicit poster and video URLs using the flat asset convention:@@ -46,7 +46,7 @@ Follow the Element Guidelines for the component itself. When using Studio-editab## 3. Register the development composition-Import and register the component in `packages/docs/src/components/Elements/element-definitions.ts` using the planned preview metadata. Set `durationInFrames` to the duration used by both the preview and the `<Sequence>` installed into Studio. Declare every external source import in `dependencies` except `react`, `react-dom`, and `remotion`, which are provided by every Remotion project; use exact versions only when the Element requires one. Add the explicit `preview` object next to the render metadata, including `posterUrl` and `videoUrl`. The URLs in this object are the source of truth for publishing; do not add a helper that derives production URLs from the Element slug.+Import and register the component in `packages/docs/src/components/Elements/element-definitions.ts` using the planned preview metadata. Set `durationInFrames` to the duration used by both the preview and the `<Sequence>` installed into Studio. Declare every external source import in `dependencies` except `react`, `react-dom`, and `remotion`, which are provided by every Remotion project. Use `version: null` for Remotion packages and an exact semantic version for every non-Remotion package; version ranges and tags are not accepted. Add the explicit `preview` object next to the render metadata, including `posterUrl` and `videoUrl`. The URLs in this object are the source of truth for publishing; do not add a helper that derives production URLs from the Element slug.Do not edit `packages/docs/src/remotion/Root.tsx`. It automatically creates a composition for every central definition using the same sizing and wrapper used by published Elements.diff --git a/packages/docs/docs/studio-protocol/create-element-payload.mdx b/packages/docs/docs/studio-protocol/create-element-payload.mdxindex aa536c7fa7..b405b15eed 100644--- a/packages/docs/docs/studio-protocol/create-element-payload.mdx+++ b/packages/docs/docs/studio-protocol/create-element-payload.mdx@@ -15,7 +15,10 @@ const payload = createElementPayload({displayName: 'Lower Third',slug: 'lower-third',sourceCode: 'export const LowerThird = () => null;',- dependencies: ['remotion'],+ dependencies: [+ {name: '@remotion/google-fonts', version: null},+ {name: 'color-namer', version: '1.4.0'},+ ],dimensions: {width: 900, height: 260},durationInFrames: 90,});@@ -39,7 +42,11 @@ The complete Element source code. It must contain exactly one exported named com### dependencies-An array of npm package names needed by the Element. Duplicate names are removed.+An array of npm packages needed by the Element. Declare each dependency as an object with `name` and `version` properties. Duplicate names are removed.++For `@remotion/*` packages, set `version` to `null`. Studio installs the version matching the Remotion project. Every non-Remotion package must specify an exact semantic version. Version ranges and tags are not accepted.++Do not declare `react`, `react-dom`, or `remotion`; every Remotion project already provides them.### dimensionsdiff --git a/packages/docs/elements/guidelines.mdx b/packages/docs/elements/guidelines.mdxindex 312567fede..01c7d4f4b1 100644--- a/packages/docs/elements/guidelines.mdx+++ b/packages/docs/elements/guidelines.mdx@@ -27,7 +27,7 @@ The caption Elements show the distinction: moving a pill between words, popping- Use stable remote asset URLs and Google Fonts for non-websafe fonts.- Avoid project-specific branding or footage, and make colors easy to change.- Minimize dependencies. [Remotion Effects](/docs/effects) are an acceptable exception.-- Declare every external dependency in the central Element definition, except `react`, `react-dom`, and `remotion`. Use exact non-Remotion versions only when required; Remotion packages use the project's installed version.+- Declare every external dependency in the central Element definition, except `react`, `react-dom`, and `remotion`. Every non-Remotion package must use an exact semantic version; version ranges and tags are not accepted. Remotion packages use `version: null` and are installed at the project's Remotion version.## Design it for compositiondiff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.tsindex c4cac0144d..26e3398f2a 100644--- a/packages/docs/src/test/elements.test.ts+++ b/packages/docs/src/test/elements.test.ts@@ -24,6 +24,8 @@ import {Seo} from '../components/Seo';const elementsRoot = path.join(__dirname, '..', '..', 'elements');const templateRoot = path.join(__dirname, '..', '..', 'elements-template');const elementDefinitionList = Object.values(elementDefinitions);+const exactVersionPattern =+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;type Element = {name: string;@@ -334,7 +336,7 @@ describe('Element preview definitions', () => {}});- test('declares every external source dependency centrally', () => {+ test('declares every external source dependency centrally with a valid version', () => {for (const element of productionElements) {const definition = elementDefinitionList.find((entry) => entry.slug === element.name,@@ -350,6 +352,27 @@ describe('Element preview definitions', () => {readFileSync(element.tsxPath, 'utf8'),).sort(),);++ for (const dependency of definition.dependencies) {+ if (dependency.name.startsWith('@remotion/')) {+ if (dependency.version !== null) {+ throw new Error(+ `${definition.slug} must use version: null for ${dependency.name}`,+ );+ }++ continue;+ }++ if (+ dependency.version === null ||+ !exactVersionPattern.test(dependency.version)+ ) {+ throw new Error(+ `${definition.slug} must declare an exact version for ${dependency.name}`,+ );+ }+ }}});diff --git a/packages/studio-protocol/src/element-drag-data.ts b/packages/studio-protocol/src/element-drag-data.tsindex 0b9dabf467..437c102909 100644--- a/packages/studio-protocol/src/element-drag-data.ts+++ b/packages/studio-protocol/src/element-drag-data.ts@@ -4,17 +4,21 @@ import {} from './component-drag-data';import {isRecord, isValidPackageName} from './validation';-export type ElementDependency = {- readonly name: string;- readonly version: string | null;-};+export type ElementDependency =+ | {+ readonly name: `@remotion/${string}`;+ readonly version: null;+ }+ | {+ readonly name: string;+ readonly version: string;+ };export type ElementDragData = {type: 'remotion-element';version: 1;element: {dependencies: ElementDependency[];- /** Absent in legacy v1 drag payloads. */durationInFrames?: number;slug: string;displayName: string;@@ -78,15 +82,46 @@ const packagesProvidedByRemotionProjects = new Set([const isExactVersion = (value: unknown): value is string =>typeof value === 'string' &&- /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(value);+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(+ value,+ );++const getElementDependencyError = (value: unknown): string | null => {+ if (+ !isRecord(value) ||+ typeof value.name !== 'string' ||+ !isValidPackageName(value.name)+ ) {+ return `Invalid Element dependency: ${JSON.stringify(value)}`;+ }++ if (packagesProvidedByRemotionProjects.has(value.name)) {+ return `${JSON.stringify(value.name)} is provided by Remotion projects and must not be declared as an Element dependency.`;+ }++ if (value.name.startsWith('@remotion/')) {+ return value.version === null+ ? null+ : `Remotion Element dependency ${JSON.stringify(value.name)} must use version: null.`;+ }++ return isExactVersion(value.version)+ ? null+ : `Non-Remotion Element dependency ${JSON.stringify(value.name)} must declare an exact version.`;+};++export function assertElementDependency(+ value: unknown,+): asserts value is ElementDependency {+ const error = getElementDependencyError(value);+ if (error !== null) {+ throw new TypeError(error);+ }+}export const isElementDependency = (value: unknown,-): value is ElementDependency =>- isRecord(value) &&- typeof value.name === 'string' &&- isValidPackageName(value.name) &&- (value.version === null || isExactVersion(value.version));+): value is ElementDependency => getElementDependencyError(value) === null;export const makeElementDragData = ({dependencies,@@ -96,33 +131,31 @@ export const makeElementDragData = ({slug,sourceCode,}: Omit<ElementDragData['element'], 'dependencies'> & {- dependencies: (ElementDependency | string)[];-}): ElementDragData => ({- type: 'remotion-element',- version: 1,- element: {- dependencies: Array.from(- new Map(- dependencies- .map((dependency) =>- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency,- )- .filter(- (dependency) =>- !packagesProvidedByRemotionProjects.has(dependency.name),- )- .map((dependency) => [dependency.name, dependency] as const),- ).values(),- ),- dimensions,- displayName,- ...(durationInFrames === undefined ? {} : {durationInFrames}),- slug,- sourceCode,- },-});+ dependencies: ElementDependency[];+}): ElementDragData => {+ for (const dependency of dependencies) {+ assertElementDependency(dependency);+ }++ return {+ type: 'remotion-element',+ version: 1,+ element: {+ dependencies: Array.from(+ new Map(+ dependencies.map(+ (dependency) => [dependency.name, dependency] as const,+ ),+ ).values(),+ ),+ dimensions,+ displayName,+ ...(durationInFrames === undefined ? {} : {durationInFrames}),+ slug,+ sourceCode,+ },+ };+};const isDimensions = (value: unknown): value is ComponentDimensions =>isRecord(value) &&@@ -157,16 +190,10 @@ export const parseElementDragData = (value: string): ElementDragData | null => {slug,sourceCode,} = parsed.element;- const normalizedDependencies =- dependencies === undefined- ? []- : Array.isArray(dependencies) && dependencies.length <= 100- ? dependencies.map((dependency) =>- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency,- )- : null;+ const validDependencies =+ Array.isArray(dependencies) && dependencies.length <= 100+ ? dependencies+ : null;if (!isSlug(slug) ||typeof displayName !== 'string' ||@@ -177,8 +204,8 @@ export const parseElementDragData = (value: string): ElementDragData | null => {sourceCode.length >= 200000 ||getElementComponentNameFromSourceCode(sourceCode) === null ||makeElementFileNameFromSlug(slug) === null ||- normalizedDependencies === null ||- !normalizedDependencies.every(isElementDependency) ||+ validDependencies === null ||+ !validDependencies.every(isElementDependency) ||(durationInFrames !== undefined && !isDuration(durationInFrames)) ||(dimensions !== undefined &&dimensions !== null &&@@ -186,7 +213,7 @@ export const parseElementDragData = (value: string): ElementDragData | null => {)return null;return makeElementDragData({- dependencies: normalizedDependencies,+ dependencies: validDependencies,dimensions: dimensions ?? null,displayName,durationInFrames,diff --git a/packages/studio-protocol/src/element-payload.ts b/packages/studio-protocol/src/element-payload.tsindex ee007ae81f..cfd3665447 100644--- a/packages/studio-protocol/src/element-payload.ts+++ b/packages/studio-protocol/src/element-payload.ts@@ -1,14 +1,14 @@import type {ComponentDimensions} from './component-drag-data';import {makeDragData} from './drag-data';import {+ assertElementDependency,getElementComponentNameFromSourceCode,- isElementDependency,makeElementFileNameFromSlug,parseElementDragData,type ElementDependency,type ElementDragData,} from './element-drag-data';-import {isRecord, isValidPackageName} from './validation';+import {isRecord} from './validation';const MAX_PAYLOAD_SIZE = 250_000;const MAX_SOURCE_CODE_SIZE = 200_000;@@ -18,7 +18,7 @@ export type CreateElementPayloadInput = {readonly displayName: string;readonly slug: string;readonly sourceCode: string;- readonly dependencies: readonly (ElementDependency | string)[];+ readonly dependencies: readonly ElementDependency[];readonly dimensions: ComponentDimensions | null;readonly durationInFrames: number;};@@ -64,14 +64,7 @@ const assertCreateElementPayloadInput = (`dependencies must contain at most ${MAX_DEPENDENCIES} packages`,);for (const dependency of input.dependencies) {- if (- (typeof dependency === 'string' && !isValidPackageName(dependency)) ||- (typeof dependency !== 'string' && !isElementDependency(dependency))- ) {- throw new TypeError(- `Invalid Element dependency: ${JSON.stringify(dependency)}`,- );- }+ assertElementDependency(dependency);}if (!isDuration(input.durationInFrames))@@ -86,11 +79,7 @@ export const createElementPayload = (assertCreateElementPayloadInput(input);const constructed = makeDragData({type: 'element',- dependencies: input.dependencies.map((dependency) =>- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency,- ),+ dependencies: [...input.dependencies],dimensions: input.dimensions,displayName: input.displayName,durationInFrames: input.durationInFrames,diff --git a/packages/studio-protocol/src/test/element-payload.test.ts b/packages/studio-protocol/src/test/element-payload.test.tsindex 3123dc70f5..4dddb33f63 100644--- a/packages/studio-protocol/src/test/element-payload.test.ts+++ b/packages/studio-protocol/src/test/element-payload.test.ts@@ -1,22 +1,26 @@import {expect, test} from 'bun:test';import {parseDragData} from '../drag-data';import {setStudioDragData} from '../drag-transport';-import {createElementPayload} from '../element-payload';+import {+ createElementPayload,+ type CreateElementPayloadInput,+} from '../element-payload';const validInput = {dependencies: [- 'react',- 'react-dom',- 'remotion',- '@remotion/google-fonts',- '@remotion/google-fonts',+ {name: '@remotion/google-fonts', version: null},+ {name: 'lodash', version: '4.17.21'},+ {name: '@remotion/google-fonts', version: null},],dimensions: {width: 800, height: 200},displayName: 'Lower Third',durationInFrames: 90,slug: 'lower-third',sourceCode: 'export const LowerThird = () => null;',-};+} satisfies CreateElementPayloadInput;++const createInvalidPayload = (input: unknown) =>+ createElementPayload(input as CreateElementPayloadInput);test('creates one canonical Element payload for HTTP and drag transports', () => {const payload = createElementPayload(validInput);@@ -25,7 +29,10 @@ test('creates one canonical Element payload for HTTP and drag transports', () =>version: 1,durationInFrames: 90,element: {- dependencies: [{name: '@remotion/google-fonts', version: null}],+ dependencies: [+ {name: '@remotion/google-fonts', version: null},+ {name: 'lodash', version: '4.17.21'},+ ],dimensions: {width: 800, height: 200},displayName: 'Lower Third',durationInFrames: 90,@@ -56,10 +63,7 @@ test('creates one canonical Element payload for HTTP and drag transports', () =>});test('rejects invalid Element authoring input with actionable errors', () => {- const cases: Array<{- input: typeof validInput;- message: string;- }> = [+ const cases: Array<{input: unknown; message: string}> = [{input: {...validInput, slug: '../unsafe'},message: 'slug must be a safe lowercase Element slug',@@ -74,8 +78,48 @@ test('rejects invalid Element authoring input with actionable errors', () => {'sourceCode must contain exactly one exported named React component',},{- input: {...validInput, dependencies: ['FS']},- message: 'Invalid Element dependency: "FS"',+ input: {...validInput, dependencies: ['@remotion/google-fonts']},+ message: 'Invalid Element dependency: "@remotion/google-fonts"',+ },+ {+ input: {+ ...validInput,+ dependencies: [{name: 'lodash', version: null}],+ },+ message:+ 'Non-Remotion Element dependency "lodash" must declare an exact version.',+ },+ {+ input: {+ ...validInput,+ dependencies: [{name: 'lodash', version: '^4.17.21'}],+ },+ message:+ 'Non-Remotion Element dependency "lodash" must declare an exact version.',+ },+ {+ input: {+ ...validInput,+ dependencies: [{name: 'lodash', version: 'latest'}],+ },+ message:+ 'Non-Remotion Element dependency "lodash" must declare an exact version.',+ },+ {+ input: {+ ...validInput,+ dependencies: [{name: '@remotion/effects', version: '4.0.0'}],+ },+ message:+ 'Remotion Element dependency "@remotion/effects" must use version: null.',+ },+ {+ input: {+ ...validInput,+ dependencies: [{name: 'react', version: '19.0.0'}],+ },+ message:+ '"react" is provided by Remotion projects and must not be declared as an Element dependency.',},{input: {...validInput, dimensions: {width: 0, height: 200}},@@ -88,6 +132,6 @@ test('rejects invalid Element authoring input with actionable errors', () => {];for (const {input, message} of cases) {- expect(() => createElementPayload(input)).toThrow(message);+ expect(() => createInvalidPayload(input)).toThrow(message);}});diff --git a/packages/studio-protocol/src/test/install-in-studio.test.ts b/packages/studio-protocol/src/test/install-in-studio.test.tsindex 02d50aade1..a2700e1384 100644--- a/packages/studio-protocol/src/test/install-in-studio.test.ts+++ b/packages/studio-protocol/src/test/install-in-studio.test.ts@@ -3,7 +3,7 @@ import {createElementPayload} from '../element-payload';import {installInStudioWithDependencies} from '../install-in-studio';const elementPayload = createElementPayload({- dependencies: ['remotion'],+ dependencies: [],dimensions: {width: 800, height: 200},displayName: 'Lower Third',durationInFrames: 90,diff --git a/packages/studio-server/src/preview-server/routes/install-dependency.ts b/packages/studio-server/src/preview-server/routes/install-dependency.tsindex 010db32617..93e356941e 100644--- a/packages/studio-server/src/preview-server/routes/install-dependency.ts+++ b/packages/studio-server/src/preview-server/routes/install-dependency.ts@@ -1,11 +1,11 @@import {spawn} from 'node:child_process';import {RenderInternals} from '@remotion/renderer';-import type {ElementDependency} from '@remotion/studio-protocol';import {extraPackages,isValidPackageName,type InstallPackageRequest,type InstallPackageResponse,+ type PackageInstallSpec,} from '@remotion/studio-shared';import {VERSION} from 'remotion/version';import {getInstallCommand} from '../../helpers/install-command';@@ -19,17 +19,14 @@ const getExtraPackageVersion = (packageName: string): string | null => {};export const getPackageInstallSpec = (- dependency: ElementDependency | string,+ dependency: PackageInstallSpec,): string => {- const {name, version} =- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency;- const extraVersion = getExtraPackageVersion(name);- if (extraVersion) return `${name}@${extraVersion}`;+ const {name, version} = dependency;if (name === 'remotion' || name.startsWith('@remotion/'))return `${name}@${VERSION}`;- return version === null ? name : `${name}@${version}`;+ if (version !== null) return `${name}@${version}`;+ const extraVersion = getExtraPackageVersion(name);+ return extraVersion === null ? name : `${name}@${extraVersion}`;};export const handleInstallPackage: ApiHandler<diff --git a/packages/studio-server/src/test/install-dependency.test.ts b/packages/studio-server/src/test/install-dependency.test.tsindex 98fd8ac5c0..2fb1ba59be 100644--- a/packages/studio-server/src/test/install-dependency.test.ts+++ b/packages/studio-server/src/test/install-dependency.test.ts@@ -3,25 +3,37 @@ import {VERSION} from 'remotion/version';import {getPackageInstallSpec} from '../preview-server/routes/install-dependency';test('uses the matching version for Remotion packages', () => {- expect(getPackageInstallSpec('remotion')).toBe(`remotion@${VERSION}`);- expect(getPackageInstallSpec('@remotion/effects')).toBe(- `@remotion/effects@${VERSION}`,+ expect(getPackageInstallSpec({name: 'remotion', version: null})).toBe(+ `remotion@${VERSION}`,);+ expect(+ getPackageInstallSpec({name: '@remotion/effects', version: null}),+ ).toBe(`@remotion/effects@${VERSION}`);});-test('uses the supported version for catalogued extra packages', () => {- expect(getPackageInstallSpec('mediabunny')).toMatch(/^mediabunny@\d/);+test('uses the supported version for unversioned catalogued packages', () => {+ expect(getPackageInstallSpec({name: 'mediabunny', version: null})).toMatch(+ /^mediabunny@\d/,+ );});-test('lets the package manager resolve other packages', () => {- expect(getPackageInstallSpec('lodash')).toBe('lodash');- expect(getPackageInstallSpec('@acme/video')).toBe('@acme/video');+test('lets the package manager resolve other unversioned packages', () => {+ expect(getPackageInstallSpec({name: 'lodash', version: null})).toBe('lodash');+ expect(getPackageInstallSpec({name: '@acme/video', version: null})).toBe(+ '@acme/video',+ );});test('uses exact declared versions for non-Remotion dependencies', () => {expect(getPackageInstallSpec({name: 'lodash', version: '4.17.21'})).toBe();+ expect(getPackageInstallSpec({name: 'mediabunny', version: '1.2.3'})).toBe(+ '[email protected]',+ );+});++test('always aligns Remotion package versions', () => {expect(getPackageInstallSpec({name: '@remotion/effects', version: '1.0.0'}),).toBe(`@remotion/effects@${VERSION}`);diff --git a/packages/studio-server/src/test/studio-protocol-routes.test.ts b/packages/studio-server/src/test/studio-protocol-routes.test.tsindex f8908d544d..11af104211 100644--- a/packages/studio-server/src/test/studio-protocol-routes.test.ts+++ b/packages/studio-server/src/test/studio-protocol-routes.test.ts@@ -255,6 +255,33 @@ test('discovers an exact Studio target and delivers one install request over HTT});expect(deliveredEvents).toHaveLength(0);+ const invalidDependencyResponse = await fetch(+ `${origin}/api/studio-protocol/install`,+ {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json',+ Origin: 'http://localhost:4000',+ },+ body: JSON.stringify({+ ...installBody,+ payload: {+ ...payload,+ element: {+ ...payload.element,+ dependencies: [{name: 'lodash', version: null}],+ },+ },+ }),+ },+ );+ expect(invalidDependencyResponse.status).toBe(400);+ expect(await invalidDependencyResponse.json()).toMatchObject({+ status: 'error',+ error: {code: 'invalid-payload'},+ });+ expect(deliveredEvents).toHaveLength(0);+const oversizedResponse = await sendUnfinishedOversizedInstallRequest(`${origin}/api/studio-protocol/install`,);diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 45ab5c8552..e9c5932d32 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -11,11 +11,7 @@ import type {X264Preset,} from '@remotion/renderer';import type {HardwareAccelerationOption} from '@remotion/renderer/client';-import type {- ComponentProp,- ElementDependency,- ElementDragData,-} from '@remotion/studio-protocol';+import type {ComponentProp, ElementDragData} from '@remotion/studio-protocol';import type {_InternalTypes,CannotUpdateSequenceReason,@@ -1012,8 +1008,13 @@ export type UpdateDefaultEditorResponse =reason: string;};+export type PackageInstallSpec = {+ readonly name: string;+ readonly version: string | null;+};+export type InstallPackageRequest = {- dependencies: ElementDependency[];+ dependencies: PackageInstallSpec[];};export type InstallPackageResponse = {};diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex 418cc37516..0eef3344ac 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -74,6 +74,7 @@ export {OpenInEditorRequest,OpenInEditorResponse,OpenInFileExplorerRequest,+ PackageInstallSpec,PasteEffectsRequest,PasteEffectsResponse,PrepareElementInstallRequest,diff --git a/packages/studio-shared/src/test/element-drag-data.test.ts b/packages/studio-shared/src/test/element-drag-data.test.tsindex b8e623c794..12cda2d697 100644--- a/packages/studio-shared/src/test/element-drag-data.test.ts+++ b/packages/studio-shared/src/test/element-drag-data.test.ts@@ -1,5 +1,10 @@import {expect, test} from 'bun:test';-import {StudioProtocolInternals} from '@remotion/studio-protocol';+import {+ StudioProtocolInternals,+ type ElementDragData,+} from '@remotion/studio-protocol';++type ElementInput = Omit<ElementDragData['element'], 'durationInFrames'>;const validElement = {dependencies: [{name: '@remotion/google-fonts', version: null}],@@ -7,23 +12,13 @@ const validElement = {displayName: 'Lower Third',sourceCode: 'export const LowerThird = () => null;',dimensions: {width: 900, height: 260},-};-const makeElementDragData = (- element:- | typeof validElement- | {- dependencies: {name: string; version: null}[];- slug: string;- displayName: string;- sourceCode: string;- dimensions: null;- },-) =>+} satisfies ElementInput;+const makeElementDragData = (element: ElementInput) =>StudioProtocolInternals.makeDragData({type: 'element',...element,durationInFrames: 120,- } as never).data;+ }).data;const parseElementDragData = (payload: string) => {let dimensions: (typeof validElement)['dimensions'] | null = null;try {@@ -45,7 +40,7 @@ const parseElementDragData = (payload: string) => {...validElement,dimensions,durationInFrames: 120,- } as never);+ });const parsed = StudioProtocolInternals.parseDragData({mimeType, payload});return parsed?.type === 'element' ? parsed.data : null;};@@ -60,7 +55,7 @@ test('parses element drag data', () => {});});-test('accepts older element drag data without dependencies', () => {+test('rejects element drag data without dependencies', () => {const {dependencies: _dependencies, ...elementWithoutDependencies} =validElement;expect(@@ -71,11 +66,7 @@ test('accepts older element drag data without dependencies', () => {element: elementWithoutDependencies,}),),- ).toEqual({- type: 'remotion-element',- version: 1,- element: {...elementWithoutDependencies, dependencies: []},- });+ ).toBe(null);});test('accepts element drag data with null dimensions', () => {@@ -174,13 +165,21 @@ test('rejects invalid element drag data', () => {}),),).toBe(null);- expect(- parseElementDragData(- JSON.stringify({- type: 'remotion-element',- version: 1,- element: {...validElement, dependencies: ['--ignore-scripts']},- }),- ),- ).toBe(null);+ for (const dependencies of [+ ['@remotion/google-fonts'],+ ['--ignore-scripts'],+ [{name: 'lodash', version: null}],+ [{name: 'lodash', version: '^4.17.21'}],+ [{name: '@remotion/effects', version: '4.0.0'}],+ ]) {+ expect(+ parseElementDragData(+ JSON.stringify({+ type: 'remotion-element',+ version: 1,+ element: {...validElement, dependencies},+ }),+ ),+ ).toBe(null);+ }});diff --git a/packages/studio/src/api/install-package.ts b/packages/studio/src/api/install-package.tsindex bb38874fc7..8bce4f0a31 100644--- a/packages/studio/src/api/install-package.ts+++ b/packages/studio/src/api/install-package.ts@@ -1,10 +1,12 @@-import type {ElementDependency} from '@remotion/studio-protocol';-import type {InstallPackageResponse} from '@remotion/studio-shared';+import type {+ InstallPackageResponse,+ PackageInstallSpec,+} from '@remotion/studio-shared';import {getRemotionEnvironment} from 'remotion';import {callApi} from '../components/call-api';export const installPackages = (- dependencies: (ElementDependency | string)[],+ dependencies: readonly PackageInstallSpec[],): Promise<InstallPackageResponse> => {if (!getRemotionEnvironment().isStudio) {throw new Error('installPackages() is only available in the Studio');@@ -15,10 +17,6 @@ export const installPackages = (}return callApi('/api/install-package', {- dependencies: dependencies.map((dependency) =>- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency,- ),+ dependencies: [...dependencies],});};diff --git a/packages/studio/src/components/InstallPackage.tsx b/packages/studio/src/components/InstallPackage.tsxindex 382fc874dc..6adf99090e 100644--- a/packages/studio/src/components/InstallPackage.tsx+++ b/packages/studio/src/components/InstallPackage.tsx@@ -69,7 +69,9 @@ export const InstallPackageModal: React.FC<{setState({type: 'installing'});try {- await installPackages(selectedPackages);+ await installPackages(+ selectedPackages.map((name) => ({name, version: null})),+ );setState({type: 'done'});} catch (err) {setState({type: 'error', error: err as Error});diff --git a/packages/studio/src/components/Timeline/TimelineFontFamilyField.tsx b/packages/studio/src/components/Timeline/TimelineFontFamilyField.tsxindex ccbe7bd32f..a208a0477e 100644--- a/packages/studio/src/components/Timeline/TimelineFontFamilyField.tsx+++ b/packages/studio/src/components/Timeline/TimelineFontFamilyField.tsx@@ -511,7 +511,9 @@ export const TimelineFontFamilyField: React.FC<{return;}- await installRequiredPackages(['@remotion/google-fonts']);+ await installRequiredPackages([+ {name: '@remotion/google-fonts', version: null},+ ]);const googleFont = getGoogleFontSourceEdit({fontFamily: option.value ?? option.label,importName: option.googleFontImportName,diff --git a/packages/studio/src/components/effect-drag-and-drop.ts b/packages/studio/src/components/effect-drag-and-drop.tsindex 6895669d8e..3712efcbc1 100644--- a/packages/studio/src/components/effect-drag-and-drop.ts+++ b/packages/studio/src/components/effect-drag-and-drop.ts@@ -60,7 +60,9 @@ export const addEffectToSequence = async ({const requiredPackage = getRequiredPackageForEffectImportPath(effect.importPath,);- await installRequiredPackages(requiredPackage ? [requiredPackage] : []);+ await installRequiredPackages(+ requiredPackage ? [{name: requiredPackage, version: null}] : [],+ );const result = await callApi('/api/add-effect', {fileName,diff --git a/packages/studio/src/helpers/install-required-package.ts b/packages/studio/src/helpers/install-required-package.tsindex 35ee33f5d8..fff408eb01 100644--- a/packages/studio/src/helpers/install-required-package.ts+++ b/packages/studio/src/helpers/install-required-package.ts@@ -1,26 +1,20 @@-import type {ElementDependency} from '@remotion/studio-protocol';+import type {PackageInstallSpec} from '@remotion/studio-shared';import {installPackages} from '../api/install-package';import {showNotification} from '../components/Notifications/NotificationCenter';let installQueue: Promise<void> = Promise.resolve();const uniqueDependencies = (- dependencies: (ElementDependency | string)[],-): ElementDependency[] =>+ dependencies: readonly PackageInstallSpec[],+): PackageInstallSpec[] =>Array.from(new Map(- dependencies.map((dependency) => {- const normalized =- typeof dependency === 'string'- ? {name: dependency, version: null}- : dependency;- return [normalized.name, normalized] as const;- }),+ dependencies.map((dependency) => [dependency.name, dependency] as const),).values(),);export const getMissingPackages = (- dependencies: (ElementDependency | string)[],+ dependencies: readonly PackageInstallSpec[],) => {const installedPackages = window.remotion_installedPackages ?? [];return uniqueDependencies(dependencies).filter(@@ -30,7 +24,7 @@ export const getMissingPackages = ();};-const addInstalledPackages = (dependencies: (ElementDependency | string)[]) => {+const addInstalledPackages = (dependencies: readonly PackageInstallSpec[]) => {const installedPackages = window.remotion_installedPackages ?? [];window.remotion_installedPackages = Array.from(new Set([@@ -40,13 +34,13 @@ const addInstalledPackages = (dependencies: (ElementDependency | string)[]) => {);};-const formatPackageList = (dependencies: ElementDependency[]) =>+const formatPackageList = (dependencies: PackageInstallSpec[]) =>dependencies.length === 1? dependencies[0]!.name: `${dependencies.length} packages`;export const installRequiredPackages = async (- dependencies: (ElementDependency | string)[],+ dependencies: readonly PackageInstallSpec[],): Promise<void> => {const runInstall = async () => {const missingPackages = getMissingPackages(dependencies);