π₯ Make videos programmatically with React
Skills: Register compositions directly in src/Root.tsx
Jonny Burgera4324f717685
diff --git a/.agents/skills/import-canvas-capture/SKILL.md b/.agents/skills/import-canvas-capture/SKILL.mdindex 9960b85421..d35c7194c4 100644--- a/.agents/skills/import-canvas-capture/SKILL.md+++ b/.agents/skills/import-canvas-capture/SKILL.md@@ -14,7 +14,8 @@ not distribute it through `packages/skills` or document the command as a stablerecording must contain embedded `REMOTION_CAPTURE_DATA` metadata; a convertedvideo that has lost this metadata cannot be imported.2. Inspect the project to find the TypeScript file containing its composition- registrations (usually `src/Root.tsx`). Choose an unused composition ID.+ registrations (usually `src/Root.tsx`). Keep all registrations directly in+ that root file. Choose an unused composition ID.3. From the target project's root, run:```sh@@ -33,8 +34,9 @@ not distribute it through `packages/skills` or document the command as a stable```4. Review the reported source files and public asset. The importer generates a- component beside the registration file, registers it, copies the video to the- public directory, and installs missing `@remotion/media` and+ video component beside the root file, inserts its `<Composition>` registration+ directly into the root, copies the video to the public directory, and installs+ missing `@remotion/media` and`@remotion/mac-cursors` dependencies at the project's Remotion version. Studiodoes not need to be running. Existing Studio sessions pick up source changesthrough their file watchers; this operation does not enter Studio's undo stack.diff --git a/packages/browser-studio/src/test/browser-studio-operations.test.ts b/packages/browser-studio/src/test/browser-studio-operations.test.tsindex 09ba051a5a..0c162e5cdd 100644--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts@@ -1459,20 +1459,20 @@ test('imports a Canvas Capture as an interactive composition', async () => {const rootFile = getProject().files['/project/src/Root.tsx'];const componentFile = getProject().files['/project/src/CanvasComp.tsx'];- expect(rootFile).toContain('<CanvasComp');+ expect(rootFile).toContain('id="CanvasComp"');+ expect(rootFile).toContain('component={CanvasComp}');expect(rootFile).toContain('import { CanvasComp } from "./CanvasComp"');expect(componentFile).toContain("src={staticFile('capture.mp4')}");expect(componentFile).toContain('<MacOSCursor');expect(componentFile).toContain('translate: interpolate(');- expect(componentFile).toContain("id={'CanvasComp'}");- expect(componentFile).toContain('width={1920}');- expect(componentFile).toContain('height={1080}');+ expect(rootFile).toContain('width={1920}');+ expect(rootFile).toContain('height={1080}');const undoResult = await operations.undo();expect(undoResult.success).toBe(true);expect(getProject().files['/project/src/CanvasComp.tsx']).toBeUndefined();expect(getProject().files['/project/src/Root.tsx']).not.toContain(- '<CanvasComp',+ 'id="CanvasComp"',);});diff --git a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts b/packages/browser-studio/src/test/browser-studio-project-operations.test.tsindex 5cc7fcc9ca..ba5ec2f87e 100644--- a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts+++ b/packages/browser-studio/src/test/browser-studio-project-operations.test.ts@@ -56,12 +56,14 @@ test('creates a Canvas Capture with both files in undo history', async () => {throw new Error(result.reason);}- expect(project.files['/project/src/Root.tsx']).toContain('<Capture />');+ expect(project.files['/project/src/Root.tsx']).toContain('id="Capture"');+ expect(project.files['/project/src/Root.tsx']).toContain(+ 'component={Capture}',+ );expect(project.files['/project/src/Root.tsx']).toMatch(/from ["']\.\/Capture["']/,);const generated = project.files['/project/src/Capture.tsx'];- expect(generated).toContain("id={'Capture'}");expect(generated).toContain("staticFile('capture.mp4')");expect(generated).toContain('<MacOSCursor');const createdProject = project;diff --git a/packages/codemods/src/add-canvas-capture-composition.ts b/packages/codemods/src/add-canvas-capture-composition.tsindex 56acc83e59..4e6a25b5b9 100644--- a/packages/codemods/src/add-canvas-capture-composition.ts+++ b/packages/codemods/src/add-canvas-capture-composition.ts@@ -1,26 +1,15 @@-import type {JSXElement} from '@babel/types';import type {CanvasCaptureData} from '@remotion/studio-shared';-import * as recast from 'recast';+import {addComposition} from './add-composition';import type {CodemodProject} from './codemod-project';import {- assertNewCompositionId,- validateMetadata,type CompositionTarget,type CompositionMetadata,type FolderReference,} from './composition-editing';-import {getRegistrationInsertionResult} from './folder-editing';import {generateCanvasCaptureComposition} from './generate-canvas-capture-composition';import {findProjectFile} from './internals';import type {CodemodInsertionResult} from './node-references';-import {getRegistrationInsertionSourceEdit} from './registration-source-edits';-import {ensureNamedImport} from './sequence-props/imports';import {parseAst} from './sequence-props/parse-ast';-import {- applySourceEdits,- captureImportSnapshots,- getInsertImportSourceEdits,-} from './source-edits';export type AddCanvasCaptureCompositionOptions<Project extends CodemodProject> =CompositionTarget & {@@ -46,14 +35,6 @@ export const addCanvasCaptureComposition = <Project extends CodemodProject>({folder,capture,}: AddCanvasCaptureCompositionOptions<Project>): CodemodInsertionResult => {- assertNewCompositionId({project, compositionFile, compositionId});- validateMetadata(metadata);- if (!/^[A-Z_$][\w$]*$/.test(component.importName)) {- throw new Error(- 'component.importName must be a named component export beginning with an uppercase letter, _ or $',- );- }-let existingComponentFile: string | null = null;try {existingComponentFile = findProjectFile({@@ -70,53 +51,21 @@ export const addCanvasCaptureComposition = <Project extends CodemodProject>({);}- const filePath = findProjectFile({project, filePath: compositionFile});- const input = project.files[filePath];- const ast = parseAst(input);- const snapshots = captureImportSnapshots(ast);- const componentName = ensureNamedImport({- ast,- importedName: component.importName,- sourcePath: component.importPath,- localName: component.importName,- });- const b = recast.types.builders;- const insertion = b.jsxElement(- b.jsxOpeningElement(b.jsxIdentifier(componentName), [], true),- null,- [],- );- const output = applySourceEdits({- input,- edits: [- getRegistrationInsertionSourceEdit({- input,- ast,- insertion: insertion as JSXElement,- folder: folder ?? null,- }),- ...getInsertImportSourceEdits({- ast,- input,- snapshots,- prettierConfigOverride: null,- }),- ],+ const result = addComposition({+ project,+ compositionFile,+ compositionId,+ component,+ metadata,+ folder,});const componentSource = generateCanvasCaptureComposition({componentName: component.importName,- compositionId,- ...metadata,+ durationInFrames: metadata.durationInFrames,+ fps: metadata.fps,...capture,});parseAst(componentSource);- const result = getRegistrationInsertionResult({- project,- filePath,- input,- output,- inserted: {type: 'last-child', folder: folder ?? null},- });return {...result,changes: [diff --git a/packages/codemods/src/generate-canvas-capture-composition.ts b/packages/codemods/src/generate-canvas-capture-composition.tsindex bc310c5b99..3470e007c2 100644--- a/packages/codemods/src/generate-canvas-capture-composition.ts+++ b/packages/codemods/src/generate-canvas-capture-composition.ts@@ -85,28 +85,22 @@ const serializeArray = (values: (string | number)[], indentation: number) => {export const generateCanvasCaptureComposition = ({componentName,- compositionId,data,durationInFrames,fps,- height,keyframeFps,videoFileName,videoHeight,videoWidth,- width,}: {readonly componentName: string;- readonly compositionId: string;readonly data: CanvasCaptureData;readonly durationInFrames: number;readonly fps: number;- readonly height: number;readonly keyframeFps: number;readonly videoFileName: string;readonly videoHeight: number;readonly videoWidth: number;- readonly width: number;}) => {const movements = collapseMouseMovementsByFrame({data, keyframeFps});if (movements.length === 0) {@@ -267,22 +261,17 @@ export const generateCanvasCaptureComposition = ({},)`;- const previewComponentName = componentName.endsWith('Composition')- ? `${componentName.slice(0, -'Composition'.length)}Preview`- : `${componentName}Preview`;-return `import {MacOSCursor} from '@remotion/mac-cursors';import {Video} from '@remotion/media';import {AbsoluteFill,- Composition,Easing,interpolate,staticFile,useCurrentFrame,} from 'remotion';-export const ${previewComponentName} = () => {+export const ${componentName} = () => {const frame = useCurrentFrame();return (@@ -314,18 +303,5 @@ ${customCursorProp} style={{</AbsoluteFill>);};--export const ${componentName} = () => {- return (- <Composition- id={${serialize(compositionId)}}- component={${previewComponentName}}- width={${width}}- height={${height}}- fps={${fps}}- durationInFrames={${durationInFrames}}- />- );-};`;};diff --git a/packages/codemods/src/test/fixtures/canvas-capture-composition.txt b/packages/codemods/src/test/fixtures/canvas-capture-composition.txtindex b3d6db1bd9..c6590bd93b 100644--- a/packages/codemods/src/test/fixtures/canvas-capture-composition.txt+++ b/packages/codemods/src/test/fixtures/canvas-capture-composition.txt@@ -2,14 +2,13 @@ import {MacOSCursor} from '@remotion/mac-cursors';import {Video} from '@remotion/media';import {AbsoluteFill,- Composition,Easing,interpolate,staticFile,useCurrentFrame,} from 'remotion';-export const CanvasCapturePreview = () => {+export const CanvasCaptureComposition = () => {const frame = useCurrentFrame();return (@@ -150,16 +149,3 @@ export const CanvasCapturePreview = () => {</AbsoluteFill>);};--export const CanvasCaptureComposition = () => {- return (- <Composition- id={'canvas-capture-promo'}- component={CanvasCapturePreview}- width={1920}- height={1080}- fps={60}- durationInFrames={500}- />- );-};diff --git a/packages/codemods/src/test/generate-canvas-capture-composition.test.ts b/packages/codemods/src/test/generate-canvas-capture-composition.test.tsindex c97881be12..fad51216d6 100644--- a/packages/codemods/src/test/generate-canvas-capture-composition.test.ts+++ b/packages/codemods/src/test/generate-canvas-capture-composition.test.ts@@ -61,7 +61,7 @@ test('creates and registers an interactive Canvas Capture composition', () => {"import {CanvasCaptureComposition} from './CanvasCaptureComposition';",);expect(getChangedContents(result, compositionFile)).toMatch(- /<Folder name="Captures">\s*<CanvasCaptureComposition \/>\s*<\/Folder>/,+ /<Folder name="Captures">\s*<Composition\s+id="canvas-capture-promo"\s+component=\{CanvasCaptureComposition\}\s+durationInFrames=\{500\}\s+fps=\{60\}\s+width=\{1920\}\s+height=\{1080\}\s*\/>\s*<\/Folder>/,);expect(result.changes.map((change) => change.filePath)).toEqual([compositionFile,diff --git a/packages/docs/docs/codemods/add-canvas-capture-composition.mdx b/packages/docs/docs/codemods/add-canvas-capture-composition.mdxindex 689a1def2e..e31621def8 100644--- a/packages/docs/docs/codemods/add-canvas-capture-composition.mdx+++ b/packages/docs/docs/codemods/add-canvas-capture-composition.mdx@@ -6,7 +6,7 @@ crumb: '@remotion/codemods'# addCanvasCaptureComposition()<AvailableFrom v="4.0.528" />-Creates an interactive Canvas Capture component and registers it in the project. Both files are returned in one result. Use [`addComposition()`](/docs/codemods/add-composition) when the component implementation already exists.+Creates an interactive Canvas Capture component and inserts a [`<Composition>`](/docs/composition) registration directly into `src/Root.tsx`. Both files are returned in one result. Use [`addComposition()`](/docs/codemods/add-composition) when the component implementation already exists.:::warning@@ -53,7 +53,7 @@ An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project### compositionFile-The existing project file containing the registration component. The same [registration-root requirements and import support](/docs/codemods/add-composition#compositionfile) as [`addComposition()`](/docs/codemods/add-composition) apply.+The existing root file containing the composition registrations, normally `src/Root.tsx`. The same [registration-root requirements and import support](/docs/codemods/add-composition#compositionfile) as [`addComposition()`](/docs/codemods/add-composition) apply.### compositionIddiff --git a/packages/docs/docs/codemods/add-composition.mdx b/packages/docs/docs/codemods/add-composition.mdxindex 58febc380d..8b6129eda3 100644--- a/packages/docs/docs/codemods/add-composition.mdx+++ b/packages/docs/docs/codemods/add-composition.mdx@@ -40,7 +40,7 @@ An in-memory [`CodemodProject`](/docs/codemods#project-model). The input project### compositionFile-The project file containing the composition registrations. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with static IDs or folder names. Aliased and namespace imports from `remotion` are supported.+The root file containing the composition registrations, normally `src/Root.tsx`. Keep all registrations directly in this file. Registration edits support [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) with static IDs or folder names. Aliased and namespace imports from `remotion` are supported.When `folder` is omitted, the file must have one component containing registrations, or a single component if no registrations exist yet. The first JSX return in the selected component is used; returns in nested functions are ignored.diff --git a/packages/docs/docs/composition.mdx b/packages/docs/docs/composition.mdxindex f16dc968fe..e2c50a65ed 100644--- a/packages/docs/docs/composition.mdx+++ b/packages/docs/docs/composition.mdx@@ -9,6 +9,8 @@ This is the component to use to register a video to make it renderable and makeA composition represents the video you want to create, as a collection of clips (for example, several `<Sequence>`) that will play back to back to form your video.+Define all [`<Composition>`](/docs/composition) and [`<Still>`](/docs/still) registrations directly in `src/Root.tsx`. Import the video components from their own files and render each registration in the root component's JSX, optionally inside a [`<Folder>`](/docs/folder).+```tsx twoslash title="src/Root.tsx"const Component: React.FC = () => null;// ---cut---@@ -27,7 +29,7 @@ export const RemotionRoot: React.FC = () => {## API-A `<Composition />` should be placed within a fragment of the root component (which is registered using [`registerRoot()`](/docs/register-root)).+A `<Composition />` should be placed in the root component, which is registered using [`registerRoot()`](/docs/register-root).The component takes the following props:@@ -95,17 +97,17 @@ If omitted, the Studio [infers basic controls from `defaultProps`](/docs/default## Example using `component`-```tsx twoslash+```tsx twoslash title="src/Root.tsx"// @allowUmdGlobalAccess// @filename: ./MyComp.tsxexport const MyComp = () => <></>;-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import {Composition} from 'remotion';import {MyComp} from './MyComp';-export const MyVideo = () => {+export const RemotionRoot = () => {return (<><Composition id="my-comp" component={MyComp} width={1080} height={1080} fps={30} durationInFrames={3 * 30} />@@ -116,8 +118,8 @@ export const MyVideo = () => {## Example using `lazyComponent`-```tsx-export const MyVideo = () => {+```tsx title="src/Root.tsx"+export const RemotionRoot = () => {return (<><Composition id="my-comp" lazyComponent={() => import('./LazyComponent')} width={1080} height={1080} fps={30} durationInFrames={3 * 30} />@@ -130,13 +132,13 @@ export const MyVideo = () => {You can use the [`<Folder />`](/docs/folder) component to organize your compositions in the sidebar.-```tsx twoslash+```tsx twoslash title="src/Root.tsx"import React from 'react';const Component: React.FC = () => null;// ---cut---import {Composition, Folder} from 'remotion';-export const Video = () => {+export const RemotionRoot = () => {return (<><Folder name="Visuals">diff --git a/packages/docs/docs/dynamic-metadata.mdx b/packages/docs/docs/dynamic-metadata.mdxindex 0785f0785d..7e937f11ec 100644--- a/packages/docs/docs/dynamic-metadata.mdx+++ b/packages/docs/docs/dynamic-metadata.mdx@@ -48,7 +48,7 @@ export const getMediaMetadata = async (src: string) => {};};-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import React from 'react';import {Composition} from 'remotion';@@ -142,7 +142,7 @@ export const getMediaMetadata = async (src: string) => {};};-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import {useEffect, useState} from 'react';import {Composition, continueRender, delayRender} from 'remotion';@@ -151,7 +151,7 @@ const VideoTesting: React.FC = () => null;// ---cut---import {getMediaMetadata} from './get-media-metadata';-export const Index: React.FC = () => {+export const RemotionRoot: React.FC = () => {const [handle] = useState(() => delayRender());const [metadata, setMetadata] = useState({durationInFrames: 1,diff --git a/packages/docs/docs/folder.mdx b/packages/docs/docs/folder.mdxindex 0d8a1cbe21..999df3ed9e 100644--- a/packages/docs/docs/folder.mdx+++ b/packages/docs/docs/folder.mdx@@ -9,15 +9,17 @@ crumb: 'API'By wrapping a [`<Composition />`](/docs/composition) inside a `<Folder />`, you can visually categorize it in your sidebar, should you have many compositions.+Keep folders and their composition registrations directly in `src/Root.tsx`.+## Example-```tsx twoslash+```tsx twoslash title="src/Root.tsx"import React from 'react';const Component: React.FC = () => null;// ---cut---import {Composition, Folder} from 'remotion';-export const Video = () => {+export const RemotionRoot = () => {return (<><Folder name="Visuals">diff --git a/packages/docs/docs/lambda/cost-example.mdx b/packages/docs/docs/lambda/cost-example.mdxindex 6297eb1b1f..989178c691 100644--- a/packages/docs/docs/lambda/cost-example.mdx+++ b/packages/docs/docs/lambda/cost-example.mdx@@ -29,7 +29,7 @@ Rendering the [`HelloWorld`](https://github.com/remotion-dev/template-helloworldThe video examples use Mediabunny's [`computeFrameRateMetrics()`](https://mediabunny.dev/api/InputVideoTrack#computeframeratemetrics) method to account for constant and variable frame rate videos.-```tsx twoslash title="OffthreadRemoteVideo.tsx"+```tsx twoslash title="src/Root.tsx"// @filename: get-media-metadata.tsimport {Input, ALL_FORMATS, UrlSource} from 'mediabunny';@@ -62,7 +62,7 @@ export const getMediaMetadata = async (src: string) => {};};-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import React from 'react';import {Video} from '@remotion/media';@@ -88,12 +88,9 @@ export const Component = () => {return <Video src={src} />;};-export const VideoFromFileComp = () => {+export const RemotionRoot = () => {return <Composition component={Component} id="VideoFromFile" calculateMetadata={calculateMetadataFn} />;};--// In Root.tsx:-// <VideoFromFileComp />```[This](https://github.com/remotion-dev/remotion/blob/main/packages/example/public/bigbuckbunny.mp4) is the video file used.@@ -105,7 +102,7 @@ Rendering a video inside your video increases the cost significantly.## Rendering a 10 minute Remote HD Video-```tsx twoslash title="OffthreadRemoteVideo.tsx"+```tsx twoslash title="src/Root.tsx"// @filename: get-media-metadata.tsimport {Input, ALL_FORMATS, UrlSource} from 'mediabunny';@@ -138,7 +135,7 @@ export const getMediaMetadata = async (src: string) => {};};-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import React from 'react';import {Video} from '@remotion/media';@@ -164,12 +161,9 @@ export const Component = () => {return <Video src={src} />;};-export const NewVideoComp = () => {+export const RemotionRoot = () => {return <Composition component={Component} id="NewVideo" calculateMetadata={calculateMetadataFn} />;};--// In Root.tsx:-// <NewVideoComp />```**Cold Lambda**: $0.108, 60.98sec@@ -177,7 +171,7 @@ export const NewVideoComp = () => {## Rendering a 10 second Remote 4K Video-```tsx twoslash title="OffthreadRemoteVideo.tsx"+```tsx twoslash title="src/Root.tsx"// @filename: get-media-metadata.tsimport {Input, ALL_FORMATS, UrlSource} from 'mediabunny';@@ -210,7 +204,7 @@ export const getMediaMetadata = async (src: string) => {};};-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import React from 'react';import {Video} from '@remotion/media';@@ -236,12 +230,9 @@ export const Component = () => {return <Video src={src} />;};-export const NewVideoComp = () => {+export const RemotionRoot = () => {return <Composition component={Component} id="NewVideo" calculateMetadata={calculateMetadataFn} />;};--// In Root.tsx:-// <NewVideoComp />```**Cold Lambda**: $0.014, 53.09secdiff --git a/packages/docs/docs/player/player-integration.mdx b/packages/docs/docs/player/player-integration.mdxindex a8e7810555..d72e55a1b9 100644--- a/packages/docs/docs/player/player-integration.mdx+++ b/packages/docs/docs/player/player-integration.mdx@@ -90,19 +90,19 @@ export const MyComp: React.FC<{text: string}> = ({text}) => {};```-Your list of videos (`remotion/Root.tsx` in the example) could look like this:+Keep all composition registrations directly in your root file (`src/remotion/Root.tsx` in this example):-```tsx twoslash+```tsx twoslash title="src/remotion/Root.tsx"// @allowUmdGlobalAccess// @filename: ./MyComp.tsxexport const MyComp = () => <></>;-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import {Composition} from 'remotion';import {MyComp} from './MyComp';-export const MyVideo = () => {+export const RemotionRoot = () => {return (<><Composition component={MyComp} durationInFrames={120} width={1920} height={1080} fps={30} id="my-comp" defaultProps={{text: 'World'}} />@@ -113,15 +113,16 @@ export const MyVideo = () => {Your index file (`remotion/index.ts` in the example) could look like this:-```tsx twoslash+```tsx twoslash title="src/remotion/index.ts"// @filename: ./Root.tsx-export const MyVideo: React.FC<{text: string}> = () => <></>;+export const RemotionRoot = () => <></>;+// @filename: index.ts// ---cut---import {registerRoot} from 'remotion';-import {MyVideo} from './Video';+import {RemotionRoot} from './Root';-registerRoot(MyVideo);+registerRoot(RemotionRoot);```:::tipdiff --git a/packages/docs/docs/register-root.mdx b/packages/docs/docs/register-root.mdxindex 7b223480cc..500c62bf9a 100644--- a/packages/docs/docs/register-root.mdx+++ b/packages/docs/docs/register-root.mdx@@ -5,7 +5,7 @@ title: registerRoot()crumb: 'API'----`registerRoot` is a function that registers the root component of the Remotion project. In the root component, one or multiple compositions should be returned (in the case of multiple compositions, they should be wrapped in a React Fragment).+`registerRoot` is a function that registers the root component of the Remotion project. Define all composition registrations directly in the root component in `src/Root.tsx`. Wrap multiple registrations in a React Fragment.:::info`registerRoot()` should live in a file that is separate from the list of compositions. This is because when using React Fast Refresh, all the code in the file that gets refreshed gets executed again, however, this function should only be called once.@@ -33,7 +33,7 @@ export default () => <></>;// @filename: MyOtherComponent.tsxexport default () => <></>;-// @filename: index.tsx+// @filename: Root.tsximport {Composition} from 'remotion';// ---cut---import MyComponent from './MyComponent';diff --git a/packages/docs/docs/still.mdx b/packages/docs/docs/still.mdxindex 744c06db8c..7e20922034 100644--- a/packages/docs/docs/still.mdx+++ b/packages/docs/docs/still.mdx@@ -7,21 +7,23 @@ crumb: 'API'A `<Still />` is a single-frame [`<Composition />`](/docs/composition). It is a convenient way to define a composition that renders an image rather than a video.+Define still registrations directly in `src/Root.tsx`, alongside your video compositions.+## ExampleThe `<Still />` component has the same API as the [`<Composition />`](/docs/composition) component, except that it's not necessary to pass `durationInFrames` and `fps`.-```tsx twoslash+```tsx twoslash title="src/Root.tsx"// @allowUmdGlobalAccess// @filename: ./MyComp.tsxexport const MyComp = () => <></>;-// @filename: index.tsx+// @filename: Root.tsx// ---cut---import {Composition, Still} from 'remotion';import {MyComp} from './MyComp';-export const MyVideo = () => {+export const RemotionRoot = () => {return (<><Composition id="my-video" component={MyComp} width={1080} height={1080} fps={30} durationInFrames={3 * 30} />diff --git a/packages/docs/docs/terminology/root-file.mdx b/packages/docs/docs/terminology/root-file.mdxindex 1121a713a2..4130e2dc94 100644--- a/packages/docs/docs/terminology/root-file.mdx+++ b/packages/docs/docs/terminology/root-file.mdx@@ -5,7 +5,9 @@ crumb: "Terminology"---The Root file is the file that exports the Root component, which renders one or more [`<Composition />`](/docs/composition) components.-By default, it is `src/Root.tsx` or `remotion/Root.tsx` in most Remotion templates, but you may reorganize the files arbitrarily.+By default, it is `src/Root.tsx`. Some templates use `remotion/Root.tsx`.++Keep all [`<Composition>`](/docs/composition), [`<Still>`](/docs/still), and [`<Folder>`](/docs/folder) registrations directly in this file. Import the components that render your videos and images from their own files.The [entry point](/docs/terminology/entry-point) will import the Root file and register it with [`registerRoot()`](/docs/register-root)diff --git a/packages/docs/docs/the-fundamentals.mdx b/packages/docs/docs/the-fundamentals.mdxindex c1e694d84d..a2ef49197d 100644--- a/packages/docs/docs/the-fundamentals.mdx+++ b/packages/docs/docs/the-fundamentals.mdx@@ -77,7 +77,7 @@ A video's first frame is `0` and its last frame is `durationInFrames - 1`.A composition is the combination of a React component and video metadata.-By rendering a [`<Composition>`](/docs/composition) component in `src/Root.tsx`, you can register a renderable video and make it visible in the Remotion sidebar.+Define all [`<Composition>`](/docs/composition) registrations directly in `src/Root.tsx` to make your videos renderable and visible in the Remotion sidebar. Import the components that render the videos from their own files.```tsx twoslash title="src/Root.tsx"import {Composition} from 'remotion';diff --git a/packages/skills/skills/remotion-captions/display-captions.md b/packages/skills/skills/remotion-captions/display-captions.mdindex db5e549473..4f1cbc4f68 100644--- a/packages/skills/skills/remotion-captions/display-captions.md+++ b/packages/skills/skills/remotion-captions/display-captions.md@@ -50,25 +50,12 @@ Give the caption area a width and position it over the video. In this1920px-wide composition, the 900px caption area is centered by translating it`(1920 - 900) / 2 = 510` pixels from the left:-```tsx+```tsx title="src/MyComposition.tsx"import { Video } from "@remotion/media";-import { Composition, Series, staticFile, useVideoConfig } from "remotion";+import { Series, staticFile, useVideoConfig } from "remotion";import { BasicCaptions } from "./basic-captions";export const MyComposition: React.FC = () => {- return (- <Composition- id="MyComposition"- component={MyComponent}- durationInFrames={750}- fps={30}- width={1920}- height={1080}- />- );-};--export const MyComponent: React.FC = () => {const { fps } = useVideoConfig();return (@@ -158,6 +145,26 @@ export const MyComponent: React.FC = () => {};```+Register the video directly in `src/Root.tsx`:++```tsx title="src/Root.tsx"+import { Composition } from "remotion";+import { MyComposition } from "./MyComposition";++export const RemotionRoot = () => {+ return (+ <Composition+ id="MyComposition"+ component={MyComposition}+ durationInFrames={750}+ fps={30}+ width={1920}+ height={1080}+ />+ );+};+```+To change a captioned clip's speed, set `playbackRate` on its shared sequence.`durationInFrames` selects a range of source frames; the group occupies `durationInFrames / playbackRate` frames in its parent timeline.Update the composition duration when changing the total timeline length.diff --git a/packages/skills/skills/remotion-create/SKILL.md b/packages/skills/skills/remotion-create/SKILL.mdindex c294e2ba82..841265e29e 100644--- a/packages/skills/skills/remotion-create/SKILL.md+++ b/packages/skills/skills/remotion-create/SKILL.md@@ -47,8 +47,10 @@ As soon as the project can run, open [Remotion Studio](../remotion-studio/SKILL.Keep the scaffold and add React Markup.Follow [Remotion React Markup Best Practices](../remotion-markup/SKILL.md) and [Video Layout Rules](video-layout.md) for video-first layout and text sizing guidance.-Before writing the root that registers `<Composition>` or `<Still>` elements,-follow [Compositions and stills](../remotion-markup/compositions.md).+Keep all `<Composition>`, `<Still>`, and `<Folder>` registrations directly in+`src/Root.tsx`, and import the video components from their own files.+Before writing the root, follow+[Compositions and stills](../remotion-markup/compositions.md).## Is this a timeline of clips?diff --git a/packages/skills/skills/remotion-interactivity/SKILL.md b/packages/skills/skills/remotion-interactivity/SKILL.mdindex 6625cae5c5..9410c73f88 100644--- a/packages/skills/skills/remotion-interactivity/SKILL.md+++ b/packages/skills/skills/remotion-interactivity/SKILL.md@@ -157,7 +157,7 @@ Register the same exported component reference that the parent renders. For theexample above, use `component={LowerThird}`, not `LowerThirdInner` or an inline wrapper.With `wrapInSequence: true`, no extra `<Sequence>` is needed for the connection.-```tsx title="Root.tsx"+```tsx title="src/Root.tsx"import {Composition} from 'remotion';import {LowerThird} from './LowerThird';diff --git a/packages/skills/skills/remotion-markup/SKILL.md b/packages/skills/skills/remotion-markup/SKILL.mdindex 48cebce73c..4d45ded7da 100644--- a/packages/skills/skills/remotion-markup/SKILL.md+++ b/packages/skills/skills/remotion-markup/SKILL.md@@ -15,6 +15,10 @@ If you detect a surprising change made in the meanwhile, don't overwrite it, ass## General rules+Keep all `<Composition>`, `<Still>`, and `<Folder>` registrations directly in+`src/Root.tsx`. Import the video components from their own files and render+the registrations in the root component's JSX.+Inside a composition or scene component, get `fps` from `useVideoConfig()` forall seconds-to-frames calculations, including timing props such as `from`,`trimBefore`, `durationInFrames`, and `premountFor`. Keeping the expression on@@ -253,8 +257,7 @@ export const LowerThird = Interactive.withSchema({});```-```tsx-// Root.tsx+```tsx title="src/Root.tsx"import { Composition } from "remotion";import { LowerThird } from "./LowerThird";import { MyScene } from "./MyScene";diff --git a/packages/skills/skills/remotion-markup/compositions.md b/packages/skills/skills/remotion-markup/compositions.mdindex bd5aa772d8..476419cf82 100644--- a/packages/skills/skills/remotion-markup/compositions.md+++ b/packages/skills/skills/remotion-markup/compositions.md@@ -7,6 +7,11 @@ metadata:A `<Composition>` defines the component, width, height, fps and duration of a renderable video.+Keep all `<Composition>`, `<Still>`, and `<Folder>` registrations directly in+`src/Root.tsx`. Import the video and image components from their own files.+Each registration should be an authored JSX node in the root component's+return, optionally inside a `<Folder>` in the same file.+## Source-editable registrationsGive each composition or still that should be edited independently in the@@ -17,12 +22,17 @@ Programmatic registration is suitable when the generated compositions areintentionally controlled as one source template and do not need to bereordered, duplicated, deleted or edited individually in the Studio.-```tsx+```tsx title="src/MyComposition.tsx"type Props = {readonly title: string;};export const MyComposition = ({title}: Props) => <h1>{title}</h1>;+```++```tsx title="src/Root.tsx"+import {Composition} from 'remotion';+import {MyComposition} from './MyComposition';export const RemotionRoot = () => {return (@@ -67,43 +77,42 @@ prop. See [Displaying captions](../remotion-captions/display-captions.md).For Studio editing, keep `defaultProps` as an inline object literal on `<Composition>` or `<Still>`.Keep values that should be written back directly in the object instead of deriving them from a loop variable.Do not store it in a variable, import it, spread it, create it with a helper, or wrap it in `satisfies`.-When scaffolding, keep the component and `<Composition>` registration in the same file so `width`, `height`, `fps`, `durationInFrames`, and `defaultProps` are visible next to the code that uses them.+Keep `width`, `height`, `fps`, `durationInFrames`, and `defaultProps` directly on each registration in `src/Root.tsx`.Use `type` declarations for props rather than `interface` to ensure `defaultProps` type safety.-```tsx-type Props = {- readonly title: string;-};--export const MyComposition = ({ title }: Props) => (- <h1>- {title}- </h1>-);+```tsx title="src/Root.tsx"+import {Composition} from 'remotion';+import {MyComposition} from './MyComposition';const defaultProps = { title: "Hello World" };-// π Inline metadata and defaults-<Composition- id="MyComposition"- component={MyComposition}- durationInFrames={100}- fps={30}- width={1080}- height={1080}- defaultProps={{ title: "Hello World" }}-/>;--// π Hidden defaults cannot be saved back by Studio-<Composition- id="OtherComposition"- component={MyComposition}- durationInFrames={100}- fps={30}- width={1080}- height={1080}- defaultProps={defaultProps}-/>;+export const RemotionRoot = () => {+ return (+ <>+ {/* π Inline metadata and defaults */}+ <Composition+ id="MyComposition"+ component={MyComposition}+ durationInFrames={100}+ fps={30}+ width={1080}+ height={1080}+ defaultProps={{ title: "Hello World" }}+ />++ {/* π Hidden defaults cannot be saved back by Studio */}+ <Composition+ id="OtherComposition"+ component={MyComposition}+ durationInFrames={100}+ fps={30}+ width={1080}+ height={1080}+ defaultProps={defaultProps}+ />+ </>+ );+};```## Folders@@ -111,7 +120,7 @@ const defaultProps = { title: "Hello World" };Use `<Folder>` to organize compositions in the sidebar.Folder names can only contain letters, numbers, and hyphens.-```tsx+```tsx title="src/Root.tsx"import { Composition, Folder } from "remotion";export const RemotionRoot = () => {@@ -136,7 +145,7 @@ export const RemotionRoot = () => {Use `<Still>` for single-frame images. It does not require `durationInFrames` or `fps`.-```tsx+```tsx title="src/Root.tsx"import { Still } from "remotion";import { Thumbnail } from "./Thumbnail";diff --git a/packages/skills/skills/remotion-markup/connected-compositions.md b/packages/skills/skills/remotion-markup/connected-compositions.mdindex bea2b835ea..9d9b1b47b2 100644--- a/packages/skills/skills/remotion-markup/connected-compositions.md+++ b/packages/skills/skills/remotion-markup/connected-compositions.md@@ -11,7 +11,7 @@ Use connected composition when a section has its own layers or timing, will be rRender the exported component directly in the parent with inline timing and editable props.It does not need an additional `<Sequence>` to connect to its registration.For consecutive scenes or transitions, render one direct instance as the only child of a `<Series.Sequence>` or `<TransitionSeries.Sequence>`.-3. Register the **same component reference** with `<Composition component={...}>` in the root.+3. Register the **same component reference** with `<Composition component={...}>` directly in `src/Root.tsx`.Give it a unique `id` and the dimensions, fps, and natural duration needed to preview the scene on its own. A `<Folder>` can keep scene compositions together.## Make the component independent of its parent@@ -106,8 +106,7 @@ export const MyVideo = () => ();```-```tsx-// Root.tsx+```tsx title="src/Root.tsx"import {Composition, Folder} from 'remotion';import {MyVideo} from './MyVideo';import {Chapter} from './Chapter';diff --git a/packages/skills/skills/remotion-markup/multi-scene-video.md b/packages/skills/skills/remotion-markup/multi-scene-video.mdindex dde81181ff..a7b1b54cf8 100644--- a/packages/skills/skills/remotion-markup/multi-scene-video.md+++ b/packages/skills/skills/remotion-markup/multi-scene-video.md@@ -47,10 +47,9 @@ export const MyVideo = () => {};```-Register the same scene components, plus the parent video, in the root:+Register the same scene components, plus the parent video, directly in `src/Root.tsx`:-```tsx-// Root.tsx+```tsx title="src/Root.tsx"import {Composition, Folder} from 'remotion';import {OpeningScene} from './OpeningScene';import {FeatureScene} from './FeatureScene';diff --git a/packages/studio-server/src/test/composition-edits.test.ts b/packages/studio-server/src/test/composition-edits.test.tsindex 05a24fbce0..e280b53a23 100644--- a/packages/studio-server/src/test/composition-edits.test.ts+++ b/packages/studio-server/src/test/composition-edits.test.ts@@ -729,7 +729,9 @@ test('addCompositionHandler creates an interactive Canvas Capture composition',expect(readFileSync(entryPoint, 'utf-8')).toContain("import {FreshCapture} from './FreshCapture'",);- expect(readFileSync(entryPoint, 'utf-8')).toContain('<FreshCapture />');+ const rootContentsAfterImport = readFileSync(entryPoint, 'utf-8');+ expect(rootContentsAfterImport).toContain('id="FreshCapture"');+ expect(rootContentsAfterImport).toContain('component={FreshCapture}');const componentContents = readFileSync(componentFile, 'utf-8');expect(componentContents).toContain("import {MacOSCursor} from '@remotion/mac-cursors'",@@ -743,9 +745,8 @@ test('addCompositionHandler creates an interactive Canvas Capture composition',);expect(componentContents).toContain('width: 1920');expect(componentContents).toContain('height: 1080');- expect(componentContents).toContain("id={'FreshCapture'}");- expect(componentContents).toContain('width={1280}');- expect(componentContents).toContain('height={720}');+ expect(rootContentsAfterImport).toContain('width={1280}');+ expect(rootContentsAfterImport).toContain('height={720}');const undoResponse = await undoHandler(getHandlerOptions({input: {}, entryPoint, remotionRoot}),