dedup fix streamscreen

This commit is contained in:
tapframe 2025-10-03 17:17:17 +05:30
parent c358c794ec
commit 7a64851256

View file

@ -498,10 +498,11 @@ export const StreamsScreen = () => {
const { colors } = currentTheme;
const { pauseTrailer, resumeTrailer } = useTrailer();
// Add ref to prevent excessive updates
// Add refs to prevent excessive updates and duplicate loads
const isMounted = useRef(true);
const loadStartTimeRef = useRef(0);
const hasDoneInitialLoadRef = useRef(false);
const isLoadingStreamsRef = useRef(false);
// CustomAlert state
const [alertVisible, setAlertVisible] = useState(false);
@ -729,9 +730,23 @@ export const StreamsScreen = () => {
// Update useEffect to check for sources
useEffect(() => {
// Reset initial load state when content changes
hasDoneInitialLoadRef.current = false;
isLoadingStreamsRef.current = false;
const checkProviders = async () => {
if (__DEV__) console.log('[StreamsScreen] checkProviders() start', { id, type, episodeId, fromPlayer });
logger.log(`[StreamsScreen] checkProviders() start id=${id} type=${type} episodeId=${episodeId || 'none'} fromPlayer=${!!fromPlayer}`);
// Prevent duplicate calls if already loading
if (isLoadingStreamsRef.current) {
if (__DEV__) console.log('[StreamsScreen] checkProviders() skipping - already loading');
return;
}
isLoadingStreamsRef.current = true;
try {
// Check for Stremio addons
const hasStremioProviders = await stremioService.hasStreamProviders();
if (__DEV__) console.log('[StreamsScreen] hasStremioProviders:', hasStremioProviders);
@ -803,6 +818,9 @@ export const StreamsScreen = () => {
}
}
}
} finally {
isLoadingStreamsRef.current = false;
}
};
checkProviders();