Skip to content

🎥 Make videos programmatically with React

class deserialization test composition

Jonny Burger8ebc2da89aa5
diff --git a/packages/example/src/ClassSerialization.tsx b/packages/example/src/ClassSerialization.tsx
new file mode 100644
index 0000000000..a7a6392f4a
--- /dev/null
+++ b/packages/example/src/ClassSerialization.tsx
@@ -0,0 +1,31 @@
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+function isClass(func: any) {
+ // Class constructor is also a function
+ if (!(func && func.constructor === Function) || func.prototype === undefined)
+ return false;
+
+ // This is a class that extends other class
+ if (Function.prototype !== Object.getPrototypeOf(func)) return true;
+
+ // Usually a function will only have 'constructor' in the prototype
+ return Object.getOwnPropertyNames(func.prototype).length > 1;
+}
+
+export const ClassSerialization: React.FC = (props) => {
+ // @ts-expect-error no types
+ console.log(props.calculated);
+ // @ts-expect-error no types
+ if (isClass(props.calculated)) {
+ throw new Error('should not result in a class');
+ }
+
+ return (
+ <div>
+ <h1>Class Deserialization</h1>
+ <p>
+ Is not supported in Remotion and will result in objects - even in the
+ studio
+ </p>
+ </div>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 62139c681f..f936413376 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -4,9 +4,9 @@ import {
CalculateMetadataFunction,
Composition,
Folder,
+ Still,
getInputProps,
staticFile,
- Still,
} from 'remotion';
import {z} from 'zod';
import {TwentyTwoKHzAudio} from './22KhzAudio';
@@ -15,6 +15,7 @@ import {NativeBufferStateForImage} from './BufferState/Image';
import {NativeBufferState} from './BufferState/Simple';
import {NativeBufferStateForVideo} from './BufferState/Video';
import {CancelRender} from './CancelRender';
+import {ClassSerialization} from './ClassSerialization';
import {ColorInterpolation} from './ColorInterpolation';
import {ComplexSounds} from './ComplexSounds';
import {MyCtx, WrappedInContext} from './Context';
@@ -32,8 +33,8 @@ import {Layers} from './Layers';
import {ManyAudio} from './ManyAudio';
import {MissingImg} from './MissingImg';
import {
- calculateMetadataFn,
OffthreadRemoteVideo,
+ calculateMetadataFn,
} from './OffthreadRemoteVideo/OffthreadRemoteVideo';
import {OrbScene} from './Orb';
import {ShapesMorph} from './Paths/ShapesMorph';
@@ -47,8 +48,8 @@ import RiveVehicle from './Rive/RiveExample';
import {ScalePath} from './ScalePath';
import {
ArrayTest,
- schemaArrayTestSchema,
SchemaTest,
+ schemaArrayTestSchema,
schemaTestSchema,
} from './SchemaTest';
import {Scripts} from './Scripts';
@@ -74,7 +75,7 @@ import {
} from './StudioApis/SaveDefaultProps';
import {TriggerCalculateMetadata} from './StudioApis/TriggerCalculateMetadata';
import {WriteStaticFile} from './StudioApis/WriteStaticFile';
-import './style.css';
+import {SubtitleArtifact} from './SubtitleArtifact/SubtitleArtifact';
import {Tailwind} from './Tailwind';
import {TenFrameTester} from './TenFrameTester';
import {TextStroke} from './TextStroke';
@@ -91,6 +92,7 @@ import {VideoSpeed} from './VideoSpeed';
import {VideoTesting} from './VideoTesting';
import {WarpDemoOuter} from './WarpText';
import {WarpDemo2} from './WarpText/demo2';
+import './style.css';
import {WatchStaticDemo} from './watch-static';
if (alias !== 'alias') {
throw new Error('should support TS aliases');
@@ -98,7 +100,23 @@ if (alias !== 'alias') {
// @ts-expect-error no types
import styles from './styles.module.scss';
-import {SubtitleArtifact} from './SubtitleArtifact/SubtitleArtifact';
+
+class Vector2 {
+ readonly x: number;
+ readonly y: number;
+
+ constructor(x: number, y: number) {
+ // eslint-disable-next-line react/no-this-in-sfc
+ this.x = x;
+ // eslint-disable-next-line react/no-this-in-sfc
+ this.y = y;
+ }
+
+ toString(): string {
+ // eslint-disable-next-line react/no-this-in-sfc
+ return `Vector2 [X: ${this.x}, Y: ${this.y}]`;
+ }
+}
if (!styles.hithere) {
throw new Error('should support SCSS modules');
@@ -457,6 +475,24 @@ export const Index: React.FC = () => {
};
}}
/>
+ <Composition
+ id="class-serialization"
+ component={ClassSerialization}
+ width={1080}
+ height={1080}
+ durationInFrames={30}
+ fps={30}
+ defaultProps={{
+ calculated: new Vector2(10, 10),
+ }}
+ calculateMetadata={() => {
+ return {
+ props: {
+ calculated: new Vector2(10, 10),
+ },
+ };
+ }}
+ />
</Folder>
<Folder name="creatives">
<Composition