@@ -128,8 +128,8 @@ export const SelfHostedVideo = ({
128128 sources,
129129 atomId,
130130 uniqueId,
131- height,
132- width,
131+ height : expectedHeight ,
132+ width : expectedWidth ,
133133 videoStyle,
134134 posterImage,
135135 fallbackImage,
@@ -158,14 +158,19 @@ export const SelfHostedVideo = ({
158158 null ,
159159 ) ;
160160 const [ hasPageBecomeActive , setHasPageBecomeActive ] = useState ( false ) ;
161-
162161 /**
163- * Keep a track of whether the video has been in view. We only
164- * want to pause the video if it has been in view.
162+ * Keeps track of whether the video has been in view.
163+ * For example, we only want to try to pause the video if it has been in view.
165164 */
166165 const [ hasBeenInView , setHasBeenInView ] = useState ( false ) ;
167166 const [ hasBeenPlayed , setHasBeenPlayed ] = useState ( false ) ;
168167 const [ hasTrackedPlay , setHasTrackedPlay ] = useState ( false ) ;
168+ /**
169+ * The actual video is a better source of truth of its dimensions.
170+ * The width and height from props are useful to prevent CLS.
171+ */
172+ const [ width , setWidth ] = useState ( expectedWidth ) ;
173+ const [ height , setHeight ] = useState ( expectedHeight ) ;
169174
170175 const VISIBILITY_THRESHOLD = 0.5 ;
171176
@@ -524,6 +529,9 @@ export const SelfHostedVideo = ({
524529 cue . line = percentFromTop ;
525530 }
526531 }
532+
533+ setWidth ( video . videoWidth ) ;
534+ setHeight ( video . videoHeight ) ;
527535 } ;
528536
529537 const handleLoadedData = ( ) => {
0 commit comments