Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii1030 committed Apr 18, 2024
1 parent 5431131 commit 6c2c0a1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ function BaseVideoPlayer({
});
}, [currentVideoPlayerRef, handleFullscreenUpdate, handlePlaybackStatusUpdate]);

// use `useLayoutEffect` instead of `useEffect` because ref is null when unmount in `useEffect` hook
// ref url: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#effect-cleanup-timing
useLayoutEffect(() =>
() => {
if(shouldUseSharedVideoElement || videoPlayerRef.current !== currentVideoPlayerRef.current) {
Expand Down Expand Up @@ -212,7 +214,7 @@ function BaseVideoPlayer({
}
return;
}

videoPlayerRef.current = currentVideoPlayerRef.current;
if (currentlyPlayingURL === url && newParentRef && 'appendChild' in newParentRef) {
newParentRef.appendChild(sharedElement as HTMLDivElement);
Expand Down

0 comments on commit 6c2c0a1

Please sign in to comment.