Skip to content

Quick Fix Summary - Mobile Persistence Issue โ€‹

The Problem โ€‹

  • Login not persisting after page refresh on Pixel
  • App feels slower
  • Sometimes works, sometimes doesn't (race condition)

Root Cause โ€‹

  1. Race condition: Persistence setup wasn't awaited before auth listener
  2. Cloudflare caching: Old JS code served even after deployment
  3. Competing async: Multiple background operations blocking main thread

The Fix (3 Changes) โ€‹

1. firebase.js - Made Persistence Synchronous โ€‹

javascript
// BEFORE: Fire and forget
setPersistence(auth, browserLocalPersistence).catch(...)

// AFTER: Wait for it
const persistencePromise = (async () => {
  await setPersistence(auth, browserLocalPersistence)
  await enableIndexedDbPersistence(db, {...})
})()

2. main.jsx - Removed Race Condition โ€‹

  • Deleted warmUpIndexedDB() call (was competing with Firebase init)
  • Service worker registration stays (non-blocking)

3. _headers - Fixed Cloudflare Caching โ€‹

/index.html
  Cache-Control: public, max-age=0, must-revalidate
  
# Added credentials support
Access-Control-Allow-Credentials: true

What You Must Do โ€‹

CRITICAL: Purge Cloudflare Cache โ€‹

Without this, old code keeps running!

  1. Go to Cloudflare Dashboard
  2. Select dev.ourlantern.app zone
  3. Caching > Purge Cache > Purge Everything
  4. Wait 2-3 minutes

Deploy โ€‹

bash
git push origin dev

Test on Pixel โ€‹

1. Clear Chrome cache: Settings > Apps > Chrome > Storage > Clear all
2. Hard refresh: Ctrl+Shift+R
3. Login
4. Force close: Settings > Apps > Chrome > Force Stop
5. Reopen
6. โœ… Should be logged in (was: login screen)

Expected Results โ€‹

MetricBeforeAfter
Login persistence50/50 chance100% works โœ…
Reload time2-3s600-800ms
BehaviorUnpredictableConsistent
FeelsSlow, buggyFast, reliable

Verify It's Working โ€‹

In Chrome DevTools Console:

javascript
firebase.auth()._persistence?.type  // Should be "LOCAL"
firebase.auth().currentUser         // Should show your user

If Still Broken โ€‹

Check Chrome Settings โ€‹

Settings > Site settings > Cookies and site data

  • Clear on exit: OFF
  • Block third-party: OFF
  • Allow all cookies: ON

Check Cloudflare Cache Was Purged โ€‹

DevTools > Network > Reload page

  • Look at index.html response headers
  • Should NOT show cf-cache-status: HIT
  • If it does: Cache wasn't purged, try again

Check Profile Type โ€‹

Settings > Accounts

  • Using personal Google account? (Not work/school)
  • Work accounts often have storage restrictions

Code Changes Summary โ€‹

src/firebase.js              โœ… Made persistence synchronous
src/main.jsx                 โœ… Removed race condition  
public/_headers              โœ… Disabled HTML caching

Build succeeds, no errors, ready to deploy โœ…

Timeline โ€‹

  1. Now: Deploy to dev branch
  2. Then: Purge Cloudflare cache (critical!)
  3. Test: On Pixel device (5 minutes)
  4. Verify: Login persists, app loads fast
  5. Deploy: To main when confident

Status: Ready for deployment ๐Ÿš€

Built with VitePress