@@ -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
@@ -311,6 +320,15 @@ export const LoopVideo = ({
311320 * Autoplay the video when it comes into view.
312321 */
313322 useEffect ( ( ) => {
323+ console . log (
324+ 'autoplay useeffect - isRestoredFromBFCache' ,
325+ isRestoredFromBFCache ,
326+ ) ;
327+ console . log (
328+ 'autoplay useeffect - isAutoplayAllowed' ,
329+ isAutoplayAllowed ,
330+ ) ;
331+
314332 if ( ! vidRef . current || isAutoplayAllowed === false ) {
315333 return ;
316334 }
@@ -331,6 +349,7 @@ export const LoopVideo = ({
331349
332350 void playVideo ( ) ;
333351 }
352+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Logs
334353 } , [
335354 isAutoplayAllowed ,
336355 isInView ,
@@ -406,8 +425,14 @@ export const LoopVideo = ({
406425
407426 useEffect ( ( ) => {
408427 window . addEventListener ( 'pageshow' , function ( event ) {
428+ console . log ( 'event' , event ) ;
409429 if ( event . persisted ) {
410430 // The page was restored from the bfcache. Rerender the component to ensure video can autoplay.
431+ console . log (
432+ 'The page was restored from the bfcache. Forcing update.' ,
433+ ) ;
434+
435+ setIsAutoplayAllowed ( null ) ;
411436 setIsRestoredFromBFCache ( true ) ;
412437 }
413438 } ) ;
0 commit comments