Bluesky app fork with some witchin' additions 💫

Try and guard against play/pause function being called after player is destroyed (#9364)

* try and guard play/pause against unmount

* add try/catch to avoid fatal crashes

authored by samuel.fm and committed by

GitHub 835a716e bb365856

+21 -7
+21 -7
src/screens/VideoFeed/index.tsx
··· 57 57 import {sanitizeDisplayName} from '#/lib/strings/display-names' 58 58 import {cleanError} from '#/lib/strings/errors' 59 59 import {sanitizeHandle} from '#/lib/strings/handles' 60 + import {logger} from '#/logger' 60 61 import {isAndroid} from '#/platform/detection' 61 62 import {useA11y} from '#/state/a11y' 62 63 import { ··· 1044 1045 const {isPlaying} = useEvent(player, 'playingChange', { 1045 1046 isPlaying: player.playing, 1046 1047 }) 1048 + const isMounted = useRef(false) 1047 1049 1048 - const togglePlayPause = () => { 1049 - if (!player) return 1050 + useEffect(() => { 1051 + isMounted.current = true 1052 + return () => { 1053 + isMounted.current = false 1054 + } 1055 + }, []) 1056 + 1057 + const togglePlayPause = useNonReactiveCallback(() => { 1058 + // gets called after a timeout, so guard against being called after unmount -sfn 1059 + if (!player || !isMounted.current) return 1050 1060 doubleTapRef.current = null 1051 - if (player.playing) { 1052 - player.pause() 1053 - } else { 1054 - player.play() 1061 + try { 1062 + if (player.playing) { 1063 + player.pause() 1064 + } else { 1065 + player.play() 1066 + } 1067 + } catch (err) { 1068 + logger.error('Could not toggle play/pause', {safeMessage: err}) 1055 1069 } 1056 - } 1070 + }) 1057 1071 1058 1072 const onPress = () => { 1059 1073 if (doubleTapRef.current) {