Skip to content

🎥 Make videos programmatically with React

Require `src` to be a string for <Audio>, <Video> and <OffthreadVideo> tags

Jonny Burger89f5c06984d2
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index aa7c1a6f6e..cd383926b4 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -22,6 +22,14 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
const {durations, setDurations} = useContext(DurationsContext);
+ if (typeof props.src !== 'string') {
+ throw new TypeError(
+ `The \`<Audio>\` tag requires a string for \`src\`, but got ${JSON.stringify(
+ props.src
+ )} instead.`
+ );
+ }
+
const onError: React.ReactEventHandler<HTMLAudioElement> = useCallback(
(e) => {
console.log(e.currentTarget.error);
diff --git a/packages/core/src/video/OffthreadVideo.tsx b/packages/core/src/video/OffthreadVideo.tsx
index 152e8806d5..63d7c53a79 100644
--- a/packages/core/src/video/OffthreadVideo.tsx
+++ b/packages/core/src/video/OffthreadVideo.tsx
@@ -15,6 +15,14 @@ export const OffthreadVideo: React.FC<
const onDuration = useCallback(() => undefined, []);
+ if (typeof props.src !== 'string') {
+ throw new TypeError(
+ `The \`<OffthreadVideo>\` tag requires a string for \`src\`, but got ${JSON.stringify(
+ props.src
+ )} instead.`
+ );
+ }
+
if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
validateStartFromProps(startFrom, endAt);
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index f044e0d609..c9773df7d7 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -24,6 +24,14 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
throw new Error('string refs are not supported');
}
+ if (typeof props.src !== 'string') {
+ throw new TypeError(
+ `The \`<Video>\` tag requires a string for \`src\`, but got ${JSON.stringify(
+ props.src
+ )} instead.`
+ );
+ }
+
const onDuration = useCallback(
(src: string, durationInSeconds: number) => {
setDurations({type: 'got-duration', durationInSeconds, src});