try and guard play/pause against unmount

This commit is contained in:
Samuel Newman
2025-11-10 13:29:48 +02:00
parent 4791486aa7
commit 187efaf359
+12 -3
View File
@@ -1044,16 +1044,25 @@ function PlayPauseTapArea({
const {isPlaying} = useEvent(player, 'playingChange', {
isPlaying: player.playing,
})
const isMounted = useRef(false)
const togglePlayPause = () => {
if (!player) return
useEffect(() => {
isMounted.current = true
return () => {
isMounted.current = false
}
}, [])
const togglePlayPause = useNonReactiveCallback(() => {
// gets called after a timeout, so guard against being called after unmount -sfn
if (!player || !isMounted.current) return
doubleTapRef.current = null
if (player.playing) {
player.pause()
} else {
player.play()
}
}
})
const onPress = () => {
if (doubleTapRef.current) {