From e3331dae96c2e3845cce3dbf886ee793c3892d55 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Sun, 12 Oct 2025 11:31:01 -0400 Subject: [PATCH] Fix: Ensure loading state is set correctly for session events in AuthProvider --- src/components/moderation/ModerationQueue.tsx | 15 ++++++++++----- src/hooks/useAuth.tsx | 15 ++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 9dbdd9b6..dfb84766 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -1185,14 +1185,19 @@ export const ModerationQueue = forwardRef((props, ref) => { console.log('📱 Tab visible - resuming queue updates'); pauseFetchingRef.current = false; - // Check admin setting for auto-refresh behavior + // CRITICAL: Check admin setting for auto-refresh behavior const shouldRefresh = refreshOnTabVisibleRef.current; - if (shouldRefresh && initialFetchCompleteRef.current && !isMountingRef.current) { - console.log('🔄 Tab became visible - triggering refresh (admin setting enabled)'); + console.log('🔍 Tab visible check - shouldRefresh setting:', shouldRefresh, + 'initialFetchComplete:', initialFetchCompleteRef.current, + 'isMounting:', isMountingRef.current); + + // Only refresh if admin setting explicitly enables it + if (shouldRefresh === true && initialFetchCompleteRef.current && !isMountingRef.current) { + console.log('🔄 Tab became visible - triggering refresh (admin setting ENABLED)'); fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current); } else { - console.log('✅ Tab became visible - resuming without refresh'); + console.log('✅ Tab became visible - NO refresh (admin setting disabled or conditions not met)'); // Realtime subscriptions will handle updates naturally } } @@ -2511,4 +2516,4 @@ export const ModerationQueue = forwardRef((props, ref) => { ); }); -ModerationQueue.displayName = 'ModerationQueue'; \ No newline at end of file +ModerationQueue.displayName = 'ModerationQueue'; diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index 5c3244c6..2264d6f3 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -189,6 +189,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) { setUser(null); setProfile(null); sessionVerifiedRef.current = false; + // CRITICAL: Set loading to false immediately when no session setLoading(false); } } else if (event === 'SIGNED_OUT') { @@ -292,7 +293,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) { } else { if (isMountedRef.current) { setProfile(null); - // If no session and this is an init event, resolve loading immediately + // CRITICAL: Always resolve loading when there's no session if (event === 'INITIAL_SESSION' || event === 'SIGNED_OUT') { console.log('[Auth] No session for event:', event, '- setting loading to false'); setLoading(false); @@ -300,11 +301,11 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) { } } - // Only set loading false immediately for events that don't need profile fetch - if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') { - console.log('[Auth] Setting loading to false immediately for event:', event); - setLoading(false); - } + // CRITICAL: Always set loading false for non-session events + if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') { + console.log('[Auth] Setting loading to false immediately for event:', event); + setLoading(false); + } }); // THEN get initial session @@ -417,4 +418,4 @@ export function useAuth() { throw new Error('useAuth must be used within an AuthProvider'); } return context; -} \ No newline at end of file +}