Skip to content

Commit

Permalink
Merge pull request #54246 from QichenZhu/fix/53904
Browse files Browse the repository at this point in the history
Fix blank modal after fullscreen video ends
  • Loading branch information
MariaHCD authored Jan 9, 2025
2 parents 3b665f7 + e842925 commit 31ac1ca
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,21 @@ function BaseVideoPlayer({
shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current, isUploading || isFullScreenRef.current);
}, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, url, isUploading, isFullScreenRef]);

// Call bindFunctions() through the refs to avoid adding it to the dependency array of the DOM mutation effect, as doing so would change the DOM when the functions update.
const bindFunctionsRef = useRef<(() => void) | null>(null);
const shouldBindFunctionsRef = useRef(false);

useEffect(() => {
bindFunctionsRef.current = bindFunctions;
if (shouldBindFunctionsRef.current) {
bindFunctions();
}
}, [bindFunctions]);

// append shared video element to new parent (used for example in attachment modal)
useEffect(() => {
shouldBindFunctionsRef.current = false;

if (url !== currentlyPlayingURL || !sharedElement || isFullScreenRef.current) {
return;
}
Expand All @@ -360,7 +373,8 @@ function BaseVideoPlayer({
videoPlayerRef.current = currentVideoPlayerRef.current;
if (currentlyPlayingURL === url && newParentRef && 'appendChild' in newParentRef) {
newParentRef.appendChild(sharedElement as HTMLDivElement);
bindFunctions();
bindFunctionsRef.current?.();
shouldBindFunctionsRef.current = true;
}
return () => {
if (!originalParent || !('appendChild' in originalParent)) {
Expand All @@ -373,7 +387,7 @@ function BaseVideoPlayer({
}
newParentRef.childNodes[0]?.remove();
};
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, isFullScreenRef, originalParent, sharedElement, shouldUseSharedVideoElement, url]);
}, [currentVideoPlayerRef, currentlyPlayingURL, isFullScreenRef, originalParent, sharedElement, shouldUseSharedVideoElement, url]);

useEffect(() => {
if (!shouldPlay) {
Expand Down

0 comments on commit 31ac1ca

Please sign in to comment.