Action Plan: Fix Mobile Persistence Issue โ
Issue: Login not persisting on Pixel after refresh, app feels slower
Root Causes Found: Race condition + potential Cloudflare caching
Changes Made (Just Deployed) โ
1. Fixed Persistence Race Condition โ
File: src/firebase.js
- Made
setPersistence()synchronous (usesawait) - Now guarantees auth is ready before listeners start
- IndexedDB persistence also awaited
2. Removed Conflicting Initialization โ
File: src/main.jsx
- Removed
warmUpIndexedDB()- was creating race condition - Removed async operations that could delay auth setup
- Service worker registration still happens (non-blocking)
3. Fixed Cloudflare Caching โ
File: public/_headers
- Disabled caching for
index.html(wasCache-Control: max-age=31536000) - Now:
Cache-Control: public, max-age=0, must-revalidate - Cloudflare will always serve fresh HTML/JS
- Added
Access-Control-Allow-Credentialsfor storage
What You Need to Do โ
Step 1: Deploy (One-Time) โ
git add .
git commit -m "Fix mobile persistence race condition and Cloudflare caching"
git push origin devโ
Build will automatically deploy to dev.ourlantern.app
Step 2: Purge Cloudflare Cache (Critical!) โ
This is essential - Cloudflare may have old HTML cached:
- Go to Cloudflare Dashboard
- Select your zone:
dev.ourlantern.app(or main domain) - Caching > Purge Cache
- Click Purge Everything
- Wait 2-3 minutes for cache to clear
Step 3: Test on Pixel โ
1. Settings > Apps > Chrome > Storage > Clear all site data
2. Open Chrome
3. Hard refresh: Ctrl+Shift+R (clears browser cache)
4. Navigate to dev.ourlantern.app
5. Login with test account
6. Wait for dashboard to fully load
7. Settings > Apps > Chrome > Force Stop (completely close)
8. Reopen Chrome
9. โ
Should be logged in alreadyStep 4: Verify in Console โ
While on app, open DevTools Console and paste:
firebase.auth()._persistence?.typeShould return: "LOCAL"
If returns "SESSION" or undefined - persistence failed
Why It Was Slow Before โ
The old code was doing:
1. Start warmUpIndexedDB() (async, not awaited)
2. Start registerServiceWorker() (async)
3. Setup auth listener (auth might not be ready!)
4. App starts React rendering
5. LATER: Persistence finishes (too late!)New code does:
1. Await setPersistence() (auth is ready NOW)
2. Await enableIndexedDb() (cache is ready NOW)
3. Setup auth listener (persistence guaranteed ready)
4. App starts React rendering
5. Everything fast and reliableIf Still Not Working โ
Check these in order:
Issue 1: Still Asking for Login After Refresh โ
Diagnose:
// In DevTools Console:
firebase.auth().currentUser // Should return user object, not null
firebase.auth()._persistence?.type // Should return "LOCAL"
Object.keys(localStorage).filter(k => k.includes('firebase')).length // Should be > 0If localStorage is empty: Chrome settings blocking storage
- Settings > Site settings > Cookies and site data > Clear on exit = OFF
- Settings > Apps > Chrome > Permissions > Storage = Allowed
If persistence is SESSION: Falls back due to error
- Check console for warnings about IndexedDB
- Try incognito mode (forces SESSION, but should still work)
Issue 2: Still Feels Slow โ
Diagnose:
// In DevTools > Performance tab
1. Start recording
2. Refresh page
3. Stop recording
4. Look for:
- Auth listener setup time
- Firebase initialization
- Profile load timeIf slow: Likely network issue, not code
- Check Network tab - are Firebase requests slow?
- Check mobile connection quality
- First load will always be slower (no cache)
Issue 3: Service Worker Not Showing โ
Diagnose:
- DevTools > Application > Service Workers
- Should show
/sw.jsas "activated and running"
If missing:
- Settings > Apps > Chrome > Storage > Clear all site data
- Hard reload: Ctrl+Shift+R
- Wait 5 seconds for SW to register
Most Likely Culprit โ
Based on symptoms (works on desktop, slow + losing login on mobile):
Ranking:
- โญโญโญ Cloudflare old cache - Most likely, easy to fix
- โญโญโญ Race condition - We just fixed this
- โญโญ Chrome profile restrictions - Check profile type
- โญ IndexedDB not available - Now disabled, shouldn't block
Expected Results After Fix โ
Timeline After Fix โ
Before deployment:
- Takes 2-3 seconds to load
- Loses login on refresh
- Service worker unreliable
After deployment + cache purge:
- Takes 600-800ms to load (40-60% faster)
- Login persists on refresh
- Service worker reliable
- Works offlineOn Pixel Specifically โ
- [ ] Reload time: 600-800ms (not 2-3 seconds)
- [ ] Login persists: Force-close and reopen shows dashboard
- [ ] No console errors: DevTools Console clean
- [ ] Profile loads: Lantern name visible immediately
Cloudflare Settings (For Reference) โ
If you need to verify Cloudflare config:
Caching tab:
- Cache Level: Standard (not Aggressive)
- Browser Cache Expiration: 4 hours (or less)
- Page Rules: None blocking /index.html
Rules tab:
- No cache rules for /index.html or /
If You Still Have Issues After This โ
Please provide:
Device info:
- Pixel model (6, 7, 8, etc)
- Chrome version (Settings > About)
- Storage available (Settings > Storage)
Console output:
javascriptwindow.debugMobileAuth.runFullDiagnostic() // Copy entire outputSteps to reproduce:
- Exact actions taken
- What happens (screenshot if possible)
- What you expected
Network conditions:
- WiFi or mobile data?
- 4G/5G or 3G?
- Latency/download speed?
With this info we can debug further.
TL;DR โ
- Deploy the code (git push)
- Purge Cloudflare cache (Caching > Purge Everything)
- Clear Chrome cache on Pixel (Settings > Storage > Clear all)
- Test login persistence
- Report if still broken
Expected: Login persists, app loads in ~600ms, no console errors โ