@@ -113,7 +113,7 @@ export const LoopVideo = ({
113113 const [ isAutoplayAllowed , setIsAutoplayAllowed ] = useState < boolean | null > (
114114 null ,
115115 ) ;
116- const [ isRestoredFromBFCache , setIsRestoredFromBFCache ] = useState ( false ) ;
116+ const [ isRestoredFromBFCache , setIsRestoredFromBFCache ] = useState ( 0 ) ;
117117
118118 /**
119119 * Keep a track of whether the video has been in view. We only
@@ -197,6 +197,10 @@ export const LoopVideo = ({
197197 * 2. Creates event listeners to control playback when there are multiple videos.
198198 */
199199 useEffect ( ( ) => {
200+ console . log (
201+ 'Setup useeffect - isRestoredFromBFCache' ,
202+ isRestoredFromBFCache ,
203+ ) ;
200204 /**
201205 * The user indicates a preference for reduced motion: https://web.dev/articles/prefers-reduced-motion
202206 */
@@ -211,9 +215,14 @@ export const LoopVideo = ({
211215 * `autoplayPreference` is explicitly `false`
212216 * when the user has said they don't want autoplay video.
213217 */
218+ console . log ( 'Setup useeffect 1 - isAutoplayAllowed' , isAutoplayAllowed ) ;
214219 setIsAutoplayAllowed (
215220 ! userPrefersReducedMotion && autoplayPreference !== false ,
216221 ) ;
222+ console . log (
223+ 'Setup useeffect 2 - isAutoplayAllowed' ,
224+ ! userPrefersReducedMotion && autoplayPreference !== false ,
225+ ) ;
217226
218227 /**
219228 * Mutes the current video when another video is unmuted
@@ -259,6 +268,7 @@ export const LoopVideo = ({
259268 handleCustomPlayYoutubeEvent ,
260269 ) ;
261270 } ;
271+ // eslint-disable-next-line react-hooks/exhaustive-deps -- logs
262272 } , [ uniqueId , isRestoredFromBFCache ] ) ;
263273
264274 /**
@@ -311,10 +321,23 @@ export const LoopVideo = ({
311321 * Autoplay the video when it comes into view.
312322 */
313323 useEffect ( ( ) => {
324+ console . log (
325+ 'autoplay useeffect - isRestoredFromBFCache' ,
326+ isRestoredFromBFCache ,
327+ ) ;
328+ console . log (
329+ 'autoplay useeffect - isAutoplayAllowed' ,
330+ isAutoplayAllowed ,
331+ ) ;
332+
314333 if ( ! vidRef . current || isAutoplayAllowed === false ) {
315334 return ;
316335 }
317336
337+ console . log ( 'autoplay useeffect - isInView' , isInView ) ;
338+ console . log ( 'autoplay useeffect - isPlayable' , isPlayable ) ;
339+ console . log ( 'autoplay useeffect - playerState' , playerState ) ;
340+
318341 if (
319342 isInView &&
320343 isPlayable &&
@@ -329,8 +352,10 @@ export const LoopVideo = ({
329352 ophanTrackerWeb ( atomId , 'loop' ) ( 'play' ) ;
330353 }
331354
355+ console . log ( 'autoplay useeffect - Playing video!' ) ;
332356 void playVideo ( ) ;
333357 }
358+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Logs
334359 } , [
335360 isAutoplayAllowed ,
336361 isInView ,
@@ -406,11 +431,20 @@ export const LoopVideo = ({
406431
407432 useEffect ( ( ) => {
408433 window . addEventListener ( 'pageshow' , function ( event ) {
434+ console . log ( 'event' , event ) ;
409435 if ( event . persisted ) {
410436 // The page was restored from the bfcache. Rerender the component to ensure video can autoplay.
411- setIsRestoredFromBFCache ( true ) ;
437+ console . log (
438+ 'The page was restored from the bfcache. Forcing update.' ,
439+ ) ;
440+ console . log ( 'bfcache useEffect - playerState' , playerState ) ;
441+ console . log ( 'bfcache useEffect - isPlayable' , isPlayable ) ;
442+
443+ setIsAutoplayAllowed ( null ) ;
444+ setIsRestoredFromBFCache ( ( prev ) => prev + 1 ) ;
412445 }
413446 } ) ;
447+ // eslint-disable-next-line react-hooks/exhaustive-deps -- logs
414448 } , [ ] ) ;
415449
416450 if ( renderingTarget !== 'Web' ) return null ;
@@ -421,6 +455,7 @@ export const LoopVideo = ({
421455
422456 const handleCanPlay = ( ) => {
423457 if ( ! isPlayable ) {
458+ console . log ( 'Setting video as playable' ) ;
424459 setIsPlayable ( true ) ;
425460 }
426461 } ;
0 commit comments