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
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);
}
});