File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
dotcom-rendering/src/components Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -110,10 +110,10 @@ export const LoopVideo = ({
110110 const [ currentTime , setCurrentTime ] = useState ( 0 ) ;
111111 const [ playerState , setPlayerState ] =
112112 useState < ( typeof PLAYER_STATES ) [ number ] > ( 'NOT_STARTED' ) ;
113-
114113 const [ isAutoplayAllowed , setIsAutoplayAllowed ] = useState < boolean | null > (
115114 null ,
116115 ) ;
116+ const [ isRestoredFromBFCache , setIsRestoredFromBFCache ] = useState ( false ) ;
117117
118118 /**
119119 * Keep a track of whether the video has been in view. We only
@@ -259,7 +259,7 @@ export const LoopVideo = ({
259259 handleCustomPlayYoutubeEvent ,
260260 ) ;
261261 } ;
262- } , [ uniqueId ] ) ;
262+ } , [ uniqueId , isRestoredFromBFCache ] ) ;
263263
264264 /**
265265 * Initiates attention tracking for ophan
@@ -404,6 +404,15 @@ export const LoopVideo = ({
404404 setPreloadPartialData ( isAutoplayAllowed === false || ! ! isInView ) ;
405405 } , [ isAutoplayAllowed , isInView ] ) ;
406406
407+ useEffect ( ( ) => {
408+ window . addEventListener ( 'pageshow' , function ( event ) {
409+ if ( event . persisted ) {
410+ // The page was restored from the bfcache. Rerender the component to ensure video can autoplay.
411+ setIsRestoredFromBFCache ( true ) ;
412+ }
413+ } ) ;
414+ } , [ ] ) ;
415+
407416 if ( renderingTarget !== 'Web' ) return null ;
408417
409418 if ( adapted ) {
You can’t perform that action at this time.
0 commit comments