From 57036aaffb8def2c25f37ddd57a9c5365682fe0b Mon Sep 17 00:00:00 2001 From: tapframe Date: Sun, 28 Sep 2025 10:43:35 +0530 Subject: [PATCH] app opening glitch fix --- src/contexts/AccountContext.tsx | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/contexts/AccountContext.tsx b/src/contexts/AccountContext.tsx index 85c4cfb..0359d3e 100644 --- a/src/contexts/AccountContext.tsx +++ b/src/contexts/AccountContext.tsx @@ -49,32 +49,20 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child // Auth state listener const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => { - // Do not block UI on auth transitions setLoading(true); try { const fullUser = session?.user ? await accountService.getCurrentUser() : null; setUser(fullUser); - // Immediately clear loading so UI can transition to MainTabs/Auth - setLoading(false); if (fullUser) { - // Run sync in background without blocking UI - setTimeout(async () => { - try { - await syncService.migrateLocalScopeToUser(); - await new Promise(r => setTimeout(r, 0)); - await syncService.subscribeRealtime(); - await new Promise(r => setTimeout(r, 0)); - await syncService.fullPull(); - await new Promise(r => setTimeout(r, 0)); - await syncService.fullPush(); - } catch (error) { - console.warn('[AccountContext] Background sync failed:', error); - } - }, 0); + await syncService.migrateLocalScopeToUser(); + await syncService.subscribeRealtime(); + // Pull first to hydrate local state, then push to avoid wiping server with empty local + await syncService.fullPull(); + await syncService.fullPush(); } else { syncService.unsubscribeRealtime(); } - } catch (e) { + } finally { setLoading(false); } });