diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index c871628f65e7..3e078d28e7ef 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -95,7 +95,7 @@ function AttachmentView({ isHovered, optionalVideoDuration, }) { - const {updateCurrentlyPlayingURL} = usePlaybackContext(); + const {updateCurrentlyPlayingURL, currentVideoPlayerRef} = usePlaybackContext(); const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -109,6 +109,17 @@ function AttachmentView({ updateCurrentlyPlayingURL(isVideo ? source : null); }, [isFocused, isVideo, source, updateCurrentlyPlayingURL, file, isUsedInAttachmentModal]); + // This should ensure we clean up any video references when closing the attachment modal as these only existed here in memory during attachment preview. + useEffect( + () => () => { + if (!isVideo) { + return; + } + currentVideoPlayerRef.current = null; + }, + [isVideo, currentVideoPlayerRef], + ); + const [imageError, setImageError] = useState(false); useNetwork({onReconnect: () => setImageError(false)});