Skip to content

Commit eb0af2c

Browse files
Programcodeclaude
andcommitted
Review fix: a gone Debate tab never re-indexes its old debate in Spotlight
Retry and the reload after a delete run without the focus guard, and an unmounted dashboard keeps its old Current Debate, so a late document read could index debate A over B. Indexing now also requires the dashboard to still be mounted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e98eecc commit eb0af2c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎apps/mobile/src/app/(tabs)/(debate)/index.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Link, useFocusEffect, useRouter } from 'expo-router';
2-
import { useCallback, useRef, useState } from 'react';
2+
import { useCallback, useEffect, useRef, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { Pressable, StyleSheet, View } from 'react-native';
55
import Animated from 'react-native-reanimated';
@@ -220,6 +220,15 @@ function DebateDetails({ debateId, dashboard = false }: { debateId: string; dash
220220
const { current } = useDebates();
221221
const currentRef = useRef(current);
222222
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+
}, []);
223232
const [view, setView] = useState<DebateSide>('pro');
224233
const [counts, setCounts] = useState<DebateCounts | null>(null);
225234
const [recent, setRecent] = useState<Record<DebateSide, DebateItem[]> | null>(null);
@@ -250,7 +259,7 @@ function DebateDetails({ debateId, dashboard = false }: { debateId: string; dash
250259
const motion = shown.motion;
251260
fetchDocumentsForSpotlight(userId, debateId, SPOTLIGHT_LIMIT)
252261
.then((documents) => {
253-
if (!isCurrent() || currentRef.current?.id !== debateId) return;
262+
if (!mounted.current || !isCurrent() || currentRef.current?.id !== debateId) return;
254263
void indexForSpotlight('work', spotlightWorkItems(documents, motion, (kind) => t(`debate.kinds.${kind}`)));
255264
})
256265
.catch((cause: unknown) => console.warn('Could not read documents for Spotlight:', cause instanceof Error ? cause.message : cause));

0 commit comments

Comments
 (0)