Skip to content

🎥 Make videos programmatically with React

Revert "Elements: Preserve Element duration in Browser Studio"

Igor Samokhovets6e85e27a021c
diff --git a/packages/browser-studio/e2e/app.tsx b/packages/browser-studio/e2e/app.tsx
index 7c29391385..6cef3cbca1 100644
--- a/packages/browser-studio/e2e/app.tsx
+++ b/packages/browser-studio/e2e/app.tsx
@@ -19,9 +19,7 @@ const render = async () => {
? await loadGitHubRepository({
repoUrl: 'https://github.com/remotion-dev/opfs-fixture',
})
- : createBlankTemplateProject({
- durationInFrames: initialElementPayload?.durationInFrames ?? null,
- });
+ : createBlankTemplateProject();
(
window as typeof window & {
__browserStudioProject: VirtualProject;
diff --git a/packages/browser-studio/e2e/browser-studio.test.ts b/packages/browser-studio/e2e/browser-studio.test.ts
index c1f89b36af..e4dd251d97 100644
--- a/packages/browser-studio/e2e/browser-studio.test.ts
+++ b/packages/browser-studio/e2e/browser-studio.test.ts
@@ -1007,7 +1007,7 @@ test('confirms and imports an Element payload from the URL fragment', async ({
dependencies: [{name: '@remotion/shapes', version: null}],
dimensions: {height: 180, width: 320},
displayName: 'Linked Element',
- durationInFrames: 150,
+ durationInFrames: 60,
installationMode: 'wrapped',
slug: 'linked-element',
sourceCode: `import {Rect} from '@remotion/shapes';
@@ -1073,20 +1073,6 @@ export const LinkedElement = () => <Rect width={320} height={180} fill="red" />;
composition: expect.stringContaining('<LinkedElement />'),
element: expect.stringContaining("import {Rect} from '@remotion/shapes'"),
});
- const composition = await page.evaluate(() => {
- const browserWindow = window as typeof window & {
- __browserStudioProject: {files: Record<string, string>};
- };
- return browserWindow.__browserStudioProject.files[
- '/project/src/Composition.tsx'
- ];
- });
- expect(composition).toMatch(
- /<Composition\b(?=[^>]*\bdurationInFrames=\{150\})[^>]*\/>/,
- );
- expect(composition).toMatch(
- /<Sequence\b(?=[^>]*\bdurationInFrames=\{150\})[^>]*>/,
- );
expect(
await studio.locator('body').evaluate(
() =>
diff --git a/packages/browser-studio/src/templates/blank.ts b/packages/browser-studio/src/templates/blank.ts
index f367a5005f..8b959abac3 100644
--- a/packages/browser-studio/src/templates/blank.ts
+++ b/packages/browser-studio/src/templates/blank.ts
@@ -1,7 +1,22 @@
import type {VirtualProject} from '../types';
-const makeBlankCompositionFile = (durationInFrames: number) =>
- `import { CalculateMetadataFunction, Composition } from "remotion";
+export const blankTemplateFiles = {
+ '/project/src/index.ts': `import { registerRoot } from "remotion";
+import { RemotionRoot } from "./Root";
+
+registerRoot(RemotionRoot);
+`,
+ '/project/src/Root.tsx': `import { MyComposition } from "./Composition";
+
+export const RemotionRoot: React.FC = () => {
+ return (
+ <>
+ <MyComposition />
+ </>
+ );
+};
+`,
+ '/project/src/Composition.tsx': `import { CalculateMetadataFunction, Composition } from "remotion";
type Props = {};
@@ -14,7 +29,7 @@ export const MyComposition = () => {
<Composition
id="MyComp"
component={MyComponent}
- durationInFrames={${durationInFrames}}
+ durationInFrames={60}
fps={30}
width={1280}
height={720}
@@ -26,25 +41,7 @@ export const MyComposition = () => {
export const MyComponent: React.FC<Props> = () => {
return null;
};
-`;
-
-export const blankTemplateFiles = {
- '/project/src/index.ts': `import { registerRoot } from "remotion";
-import { RemotionRoot } from "./Root";
-
-registerRoot(RemotionRoot);
-`,
- '/project/src/Root.tsx': `import { MyComposition } from "./Composition";
-
-export const RemotionRoot: React.FC = () => {
- return (
- <>
- <MyComposition />
- </>
- );
-};
`,
- '/project/src/Composition.tsx': makeBlankCompositionFile(60),
'/project/package.json': `{
"name": "template-empty",
"version": "1.0.0",
@@ -106,27 +103,8 @@ Config.setOverwriteOutput(true);
`,
} as const;
-export const createBlankTemplateProject = (
- {durationInFrames}: {readonly durationInFrames: number | null} = {
- durationInFrames: null,
- },
-): VirtualProject => {
- const resolvedDurationInFrames = durationInFrames ?? 60;
- if (
- !Number.isInteger(resolvedDurationInFrames) ||
- resolvedDurationInFrames <= 0
- ) {
- throw new TypeError('durationInFrames must be a positive integer');
- }
-
- return {
- rootDir: '/project',
- entryPoint: '/project/src/index.ts',
- files: {
- ...blankTemplateFiles,
- '/project/src/Composition.tsx': makeBlankCompositionFile(
- resolvedDurationInFrames,
- ),
- },
- };
-};
+export const createBlankTemplateProject = (): VirtualProject => ({
+ rootDir: '/project',
+ entryPoint: '/project/src/index.ts',
+ files: {...blankTemplateFiles},
+});
diff --git a/packages/browser-studio/src/test/template-blank.test.ts b/packages/browser-studio/src/test/template-blank.test.ts
index 91be6ed6e7..7bfa82cbee 100644
--- a/packages/browser-studio/src/test/template-blank.test.ts
+++ b/packages/browser-studio/src/test/template-blank.test.ts
@@ -37,15 +37,10 @@ test('blank template virtual files match the source template', () => {
);
});
-test('createBlankTemplateProject uses the requested composition duration', () => {
+test('createBlankTemplateProject points to the virtual entry point', () => {
expect(createBlankTemplateProject()).toEqual({
rootDir: '/project',
entryPoint: '/project/src/index.ts',
files: {...blankTemplateFiles},
});
-
- const project = createBlankTemplateProject({durationInFrames: 150});
- expect(project.files['/project/src/Composition.tsx']).toContain(
- 'durationInFrames={150}',
- );
});
diff --git a/packages/docs/standalone/experimental-new/index.tsx b/packages/docs/standalone/experimental-new/index.tsx
index ee7bcff167..7e3ef66c36 100644
--- a/packages/docs/standalone/experimental-new/index.tsx
+++ b/packages/docs/standalone/experimental-new/index.tsx
@@ -76,22 +76,10 @@ type ProjectState =
}
| {type: 'error'; repoUrl: string; message: string};
-const createBlankProject = (
- initialElementState: InitialElementState,
-): VirtualProject =>
- createBlankTemplateProject({
- durationInFrames:
- initialElementState.type === 'payload'
- ? initialElementState.payload.payload.durationInFrames
- : null,
- });
-
-const getInitialProjectState = (
- initialElementState: InitialElementState,
-): ProjectState => {
+const getInitialProjectState = (): ProjectState => {
const repoUrl = new URLSearchParams(window.location.search).get('repo');
if (!repoUrl) {
- return {type: 'ready', project: createBlankProject(initialElementState)};
+ return {type: 'ready', project: createBlankTemplateProject()};
}
return {
@@ -128,9 +116,7 @@ const getInitialElementState = (): InitialElementState => {
const BrowserStudioContent: React.FC = () => {
const [initialElementState] = useState(getInitialElementState);
- const [projectState, setProjectState] = useState(() =>
- getInitialProjectState(initialElementState),
- );
+ const [projectState, setProjectState] = useState(getInitialProjectState);
const loadingRepoUrl =
projectState.type === 'loading' ? projectState.repoUrl : null;
@@ -247,7 +233,7 @@ const BrowserStudioContent: React.FC = () => {
<button
onClick={() =>
setProjectState({
- project: createBlankProject(initialElementState),
+ project: createBlankTemplateProject(),
type: 'ready',
})
}