From 518a9a93e06686ba707427078a1770dc3d803b2b Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:12:37 +0200 Subject: [PATCH] fix: avoid crash when setting index to 0 to tracks selection (#3721) * fix(ts): onPlaybackRateChangeData was not correctly typed * fix: ensure tracks are well displayed in the sample * fix: avoid crash when setting invalid selected track or index 0 --- src/Video.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Video.tsx b/src/Video.tsx index 531d50f7..cc017338 100644 --- a/src/Video.tsx +++ b/src/Video.tsx @@ -193,13 +193,14 @@ const Video = forwardRef( if (!selectedTextTrack) { return; } - const value = selectedTextTrack.value - ? `${selectedTextTrack.value}` - : undefined; - + const type = typeof selectedTextTrack.value; + if (type !== 'number' && type !== 'string') { + console.log('invalid type provided to selectedTextTrack'); + return; + } return { type: selectedTextTrack?.type, - value, + value: `${selectedTextTrack.value}`, }; }, [selectedTextTrack]); @@ -207,13 +208,15 @@ const Video = forwardRef( if (!selectedAudioTrack) { return; } - const value = selectedAudioTrack.value - ? `${selectedAudioTrack.value}` - : undefined; + const type = typeof selectedAudioTrack.value; + if (type !== 'number' && type !== 'string') { + console.log('invalid type provided to selectedAudioTrack'); + return; + } return { type: selectedAudioTrack?.type, - value, + value: `${selectedAudioTrack.value}`, }; }, [selectedAudioTrack]);