Skip to content

Commit

Permalink
Merge pull request #37386 from jeremy-croff/37142
Browse files Browse the repository at this point in the history
fix(37142): unmount video ref when attachment closes
  • Loading branch information
pecanoro authored Mar 4, 2024
2 parents 49cb3b1 + cb302a8 commit 6db1843
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Attachments/AttachmentView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function AttachmentView({
isHovered,
optionalVideoDuration,
}) {
const {updateCurrentlyPlayingURL} = usePlaybackContext();
const {updateCurrentlyPlayingURL, currentVideoPlayerRef} = usePlaybackContext();
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand All @@ -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)});
Expand Down

0 comments on commit 6db1843

Please sign in to comment.