Skip to content

🎥 Make videos programmatically with React

add runtime validation for startAt and endAt prop

Shankhadeep Deya380882a8584
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index 1ee1223661..d2a260fe66 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -8,6 +8,41 @@ export const Audio: React.FC<RemotionAudioProps & RemotionMainAudioProps> = (
) => {
const {startAt, endAt, ...otherProps} = props;
if (typeof startAt !== 'undefined' || typeof endAt !== 'undefined') {
+ if (typeof startAt !== 'undefined') {
+ if (typeof startAt !== 'number') {
+ throw new TypeError(
+ `type of startAt prop is a number, instead got type ${typeof startAt}.`
+ );
+ }
+ if (startAt < 0) {
+ throw new TypeError(
+ `startAt must be greater than equal to 0 instead got ${startAt}.`
+ );
+ }
+ if (isNaN(startAt) || startAt === Infinity) {
+ throw new TypeError('startAt prop can not be NaN or Infinity.');
+ }
+ }
+ if (typeof endAt !== 'undefined') {
+ if (typeof endAt !== 'number') {
+ throw new TypeError(
+ `type of endAt prop is a number, instead got type ${typeof endAt}.`
+ );
+ }
+ if (endAt <= 0) {
+ throw new TypeError(
+ `endAt must be a positive number, instead got ${endAt}.`
+ );
+ }
+ if (isNaN(endAt)) {
+ throw new TypeError('startAt propcan not be NaN.');
+ }
+ }
+ if (typeof startAt !== 'undefined' && typeof endAt !== 'undefined') {
+ if (endAt < startAt) {
+ throw new TypeError('endAt prop must be greater than startAt prop');
+ }
+ }
const startAtFrameNo = startAt ? startAt : 0;
const endAtFrameNO = endAt ? endAt : Infinity;
return (
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index d8c92d3f3f..28b0c2ac71 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -9,8 +9,43 @@ export const Video: React.FC<RemotionVideoProps & RemotionMainVideoProps> = (
) => {
const {startAt, endAt, ...otherProps} = props;
if (typeof startAt !== 'undefined' || typeof endAt !== 'undefined') {
- const startAtFrameNo = startAt ? startAt : 0;
- const endAtFrameNO = endAt ? endAt : Infinity;
+ if (typeof startAt !== 'undefined') {
+ if (typeof startAt !== 'number') {
+ throw new TypeError(
+ `type of startAt prop is a number, instead got type ${typeof startAt}.`
+ );
+ }
+ if (startAt < 0) {
+ throw new TypeError(
+ `startAt must be greater than equal to 0 instead got ${startAt}.`
+ );
+ }
+ if (isNaN(startAt) || startAt === Infinity) {
+ throw new TypeError('startAt prop can not be NaN or Infinity.');
+ }
+ }
+ if (typeof endAt !== 'undefined') {
+ if (typeof endAt !== 'number') {
+ throw new TypeError(
+ `type of endAt prop is a number, instead got type ${typeof endAt}.`
+ );
+ }
+ if (endAt <= 0) {
+ throw new TypeError(
+ `endAt must be a positive number, instead got ${endAt}.`
+ );
+ }
+ if (isNaN(endAt)) {
+ throw new TypeError('startAt propcan not be NaN.');
+ }
+ }
+ if (typeof startAt !== 'undefined' && typeof endAt !== 'undefined') {
+ if (endAt < startAt) {
+ throw new TypeError('endAt prop must be greater than startAt prop');
+ }
+ }
+ const startAtFrameNo = typeof startAt !== 'undefined' ? startAt : 0;
+ const endAtFrameNO = typeof endAt !== 'undefined' ? endAt : Infinity;
return (
<Sequence from={0 - startAtFrameNo} durationInFrames={endAtFrameNO}>
<Video {...otherProps} />