|
1 | 1 | import { Link, useFocusEffect, useRouter } from 'expo-router'; |
2 | | -import { useCallback, useRef, useState } from 'react'; |
| 2 | +import { useCallback, useEffect, useRef, useState } from 'react'; |
3 | 3 | import { useTranslation } from 'react-i18next'; |
4 | 4 | import { Pressable, StyleSheet, View } from 'react-native'; |
5 | 5 | import Animated from 'react-native-reanimated'; |
@@ -220,6 +220,15 @@ function DebateDetails({ debateId, dashboard = false }: { debateId: string; dash |
220 | 220 | const { current } = useDebates(); |
221 | 221 | const currentRef = useRef(current); |
222 | 222 | currentRef.current = current; |
| 223 | + // Retry and the reload after a delete run with no focus guard; a component gone since then keeps an old |
| 224 | + // currentRef, so Spotlight also asks whether this one is still on screen. |
| 225 | + const mounted = useRef(true); |
| 226 | + useEffect(() => { |
| 227 | + mounted.current = true; |
| 228 | + return () => { |
| 229 | + mounted.current = false; |
| 230 | + }; |
| 231 | + }, []); |
223 | 232 | const [view, setView] = useState<DebateSide>('pro'); |
224 | 233 | const [counts, setCounts] = useState<DebateCounts | null>(null); |
225 | 234 | const [recent, setRecent] = useState<Record<DebateSide, DebateItem[]> | null>(null); |
@@ -250,7 +259,7 @@ function DebateDetails({ debateId, dashboard = false }: { debateId: string; dash |
250 | 259 | const motion = shown.motion; |
251 | 260 | fetchDocumentsForSpotlight(userId, debateId, SPOTLIGHT_LIMIT) |
252 | 261 | .then((documents) => { |
253 | | - if (!isCurrent() || currentRef.current?.id !== debateId) return; |
| 262 | + if (!mounted.current || !isCurrent() || currentRef.current?.id !== debateId) return; |
254 | 263 | void indexForSpotlight('work', spotlightWorkItems(documents, motion, (kind) => t(`debate.kinds.${kind}`))); |
255 | 264 | }) |
256 | 265 | .catch((cause: unknown) => console.warn('Could not read documents for Spotlight:', cause instanceof Error ? cause.message : cause)); |
|
0 commit comments