diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index f6a56dc73088..341b71657bbc 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -101,7 +101,7 @@ function AttachmentView({ isHovered, optionalVideoDuration, }) { - const {updateCurrentlyPlayingURL} = usePlaybackContext(); + const {updateCurrentlyPlayingURL, currentVideoPlayerRef} = usePlaybackContext(); const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -115,6 +115,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)});