perf: pause mobile host polling when hidden (#4043)

This commit is contained in:
Neil 2026-05-31 02:19:24 -07:00 committed by GitHub
parent 91e19e5c97
commit 69ec6a9c92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 13 deletions

View File

@ -9,7 +9,7 @@ import {
TextInput
} from 'react-native'
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
import { useLocalSearchParams, useRouter } from 'expo-router'
import { useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router'
import {
Search,
X,
@ -495,12 +495,6 @@ export default function HostScreen() {
}
}, [client, connState, hostId])
useEffect(() => {
if (connState === 'connected') {
void fetchWorktrees()
}
}, [connState, fetchWorktrees])
// Why: read desktop's protocol version from status.get on every connect
// and re-evaluate compatibility. If the desktop declares this mobile
// build too old (or vice versa via the local minimum), the host detail
@ -542,13 +536,18 @@ export default function HostScreen() {
}
}, [connState, client])
useEffect(() => {
if (connState !== 'connected') return
const interval = setInterval(() => {
useFocusEffect(
useCallback(() => {
if (connState !== 'connected') return
void fetchWorktrees()
}, 3000)
return () => clearInterval(interval)
}, [connState, fetchWorktrees])
// Why: React Navigation keeps previous stack screens mounted; only
// poll the host list while this route is visible.
const interval = setInterval(() => {
void fetchWorktrees()
}, 3000)
return () => clearInterval(interval)
}, [connState, fetchWorktrees])
)
const updateLocalPins = useCallback(
(worktreeId: string, pinned: boolean) => {