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', { const {isPlaying} = useEvent(player, 'playingChange', {
isPlaying: player.playing, isPlaying: player.playing,
}) })
const isMounted = useRef(false)
const togglePlayPause = () => { useEffect(() => {
if (!player) return 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 doubleTapRef.current = null
if (player.playing) { if (player.playing) {
player.pause() player.pause()
} else { } else {
player.play() player.play()
} }
} })
const onPress = () => { const onPress = () => {
if (doubleTapRef.current) { if (doubleTapRef.current) {