diff --git a/mobile/app/pair-confirm.tsx b/mobile/app/pair-confirm.tsx index 6e28b2fd4..8e95ea438 100644 --- a/mobile/app/pair-confirm.tsx +++ b/mobile/app/pair-confirm.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useRef, useState } from 'react' +import { useCallback, useRef, useState } from 'react' import { View, Text, StyleSheet, Pressable, ActivityIndicator, BackHandler } from 'react-native' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router' @@ -60,12 +60,16 @@ export default function PairConfirmScreen() { }, [cancel]) ) - useEffect(() => { - return () => { - mountedRef.current = false - activePairingAttemptRef.current?.dispose() - activePairingAttemptRef.current = null + const setPairConfirmRootRef = useCallback((node: View | null): void => { + if (node !== null) { + mountedRef.current = true + return } + // Why: pairing attempts can outlive the visible route; dispose them when + // the confirm screen detaches without a passive cleanup-only Effect. + mountedRef.current = false + activePairingAttemptRef.current?.dispose() + activePairingAttemptRef.current = null }, []) async function confirm() { @@ -155,7 +159,7 @@ export default function PairConfirmScreen() { const containerPadding = { paddingTop: insets.top + spacing.sm } return ( - +