Skip to content

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 (uses await)
  • 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 (was Cache-Control: max-age=31536000)
  • Now: Cache-Control: public, max-age=0, must-revalidate
  • Cloudflare will always serve fresh HTML/JS
  • Added Access-Control-Allow-Credentials for storage

What You Need to Do โ€‹

Step 1: Deploy (One-Time) โ€‹

bash
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:

  1. Go to Cloudflare Dashboard
  2. Select your zone: dev.ourlantern.app (or main domain)
  3. Caching > Purge Cache
  4. Click Purge Everything
  5. 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 already

Step 4: Verify in Console โ€‹

While on app, open DevTools Console and paste:

javascript
firebase.auth()._persistence?.type

Should 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 reliable

If Still Not Working โ€‹

Check these in order:

Issue 1: Still Asking for Login After Refresh โ€‹

Diagnose:

javascript
// 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 > 0

If 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:

javascript
// In DevTools > Performance tab
1. Start recording
2. Refresh page
3. Stop recording
4. Look for:
   - Auth listener setup time
   - Firebase initialization
   - Profile load time

If 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.js as "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:

  1. โญโญโญ Cloudflare old cache - Most likely, easy to fix
  2. โญโญโญ Race condition - We just fixed this
  3. โญโญ Chrome profile restrictions - Check profile type
  4. โญ 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 offline

On 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:

  1. Device info:

    • Pixel model (6, 7, 8, etc)
    • Chrome version (Settings > About)
    • Storage available (Settings > Storage)
  2. Console output:

    javascript
    window.debugMobileAuth.runFullDiagnostic()
    // Copy entire output
  3. Steps to reproduce:

    • Exact actions taken
    • What happens (screenshot if possible)
    • What you expected
  4. Network conditions:

    • WiFi or mobile data?
    • 4G/5G or 3G?
    • Latency/download speed?

With this info we can debug further.


TL;DR โ€‹

  1. Deploy the code (git push)
  2. Purge Cloudflare cache (Caching > Purge Everything)
  3. Clear Chrome cache on Pixel (Settings > Storage > Clear all)
  4. Test login persistence
  5. Report if still broken

Expected: Login persists, app loads in ~600ms, no console errors โœ…

Built with VitePress