app opening glitch fix

This commit is contained in:
tapframe 2025-09-28 10:43:35 +05:30
parent 999a33f82b
commit 57036aaffb

View file

@ -49,32 +49,20 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child
// Auth state listener // Auth state listener
const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => { const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => {
// Do not block UI on auth transitions
setLoading(true); setLoading(true);
try { try {
const fullUser = session?.user ? await accountService.getCurrentUser() : null; const fullUser = session?.user ? await accountService.getCurrentUser() : null;
setUser(fullUser); setUser(fullUser);
// Immediately clear loading so UI can transition to MainTabs/Auth
setLoading(false);
if (fullUser) { if (fullUser) {
// Run sync in background without blocking UI
setTimeout(async () => {
try {
await syncService.migrateLocalScopeToUser(); await syncService.migrateLocalScopeToUser();
await new Promise(r => setTimeout(r, 0));
await syncService.subscribeRealtime(); await syncService.subscribeRealtime();
await new Promise(r => setTimeout(r, 0)); // Pull first to hydrate local state, then push to avoid wiping server with empty local
await syncService.fullPull(); await syncService.fullPull();
await new Promise(r => setTimeout(r, 0));
await syncService.fullPush(); await syncService.fullPush();
} catch (error) {
console.warn('[AccountContext] Background sync failed:', error);
}
}, 0);
} else { } else {
syncService.unsubscribeRealtime(); syncService.unsubscribeRealtime();
} }
} catch (e) { } finally {
setLoading(false); setLoading(false);
} }
}); });