perf: move troubleshoot cleanup to root ref

This commit is contained in:
Neil 2026-05-31 09:09:45 -07:00 committed by GitHub
parent 876aba7746
commit ef5f818978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { useState, useCallback, useEffect, useRef } from 'react'
import { useState, useCallback, useRef } from 'react'
import {
View,
Text,
@ -120,13 +120,16 @@ export default function TroubleshootScreen() {
const diagnosticRunRef = useRef(0)
const activeInternetCheckRef = useRef<DiagnosticFetchTimeout | null>(null)
useEffect(() => {
return () => {
abortRef.current = true
diagnosticRunRef.current += 1
activeInternetCheckRef.current?.dispose()
activeInternetCheckRef.current = null
const setTroubleshootRootRef = useCallback((node: View | null): void => {
if (node !== null) {
return
}
// Why: diagnostics can outlive the screen; cancel the active run when the
// route detaches without a passive cleanup-only Effect.
abortRef.current = true
diagnosticRunRef.current += 1
activeInternetCheckRef.current?.dispose()
activeInternetCheckRef.current = null
}, [])
const toggleSection = useCallback((id: string) => {
@ -216,7 +219,10 @@ export default function TroubleshootScreen() {
}, [])
return (
<View style={[styles.container, { paddingTop: insets.top + spacing.sm }]}>
<View
ref={setTroubleshootRootRef}
style={[styles.container, { paddingTop: insets.top + spacing.sm }]}
>
<View style={styles.topRow}>
<Pressable style={styles.backButton} onPress={() => router.back()}>
<ChevronLeft size={22} color={colors.textSecondary} />