PWA gap: Service worker doesn't cache IndexedDB data — offline shows empty app #9

Closed
opened 2026-05-16 03:41:59 +00:00 by Mark · 2 comments
Owner

Severity: MEDIUM (PWA completeness)

Location

public/sw.js — Service Worker

Description

The service worker precaches static assets and caches JS/CSS/fonts at runtime, but does NOT cache the IndexedDB data that the app actually displays. When offline:

  • The app shell loads fine (UI chrome renders)
  • All data screens are empty because Dexie/IndexedDB reads fail
  • The app is effectively useless offline despite being installed as a PWA

The SW uses a network-first strategy for navigation, meaning every page load tries the network before falling back to cache — a poor offline UX even for the shell:

const PRECACHE_ASSETS = ['/', '/index.html', ...];  // no data cache

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then((cached) => {
      return cached || fetch(event.request).then(...)
    })
  );
  // No IndexedDB data is ever persisted to CacheStorage
});

Impact

  • Offline = an empty shell with no data
  • Unreliable connections cause frequent blank-data screens
  • The PWA install prompt is misleading: users expect installed apps to work offline
  • No background sync for reconnection

Recommendation

  1. Implement a CacheStorage snapshot of critical IndexedDB data (people list, recent interactions)
  2. Change navigation strategy to "cache-first, network refresh in background" for the app shell
  3. Consider Workbox or a similar SW library for more robust caching patterns

Code context

  • public/sw.js — full service worker
## Severity: MEDIUM (PWA completeness) ### Location `public/sw.js` — Service Worker ### Description The service worker precaches static assets and caches JS/CSS/fonts at runtime, but does NOT cache the IndexedDB data that the app actually displays. When offline: - The app shell loads fine (UI chrome renders) - All data screens are empty because Dexie/IndexedDB reads fail - The app is effectively useless offline despite being installed as a PWA The SW uses a **network-first** strategy for navigation, meaning every page load tries the network before falling back to cache — a poor offline UX even for the shell: ```javascript const PRECACHE_ASSETS = ['/', '/index.html', ...]; // no data cache self.addEventListener('fetch', (event) => { event.respondWith( caches.match(event.request).then((cached) => { return cached || fetch(event.request).then(...) }) ); // No IndexedDB data is ever persisted to CacheStorage }); ``` ### Impact - Offline = an empty shell with no data - Unreliable connections cause frequent blank-data screens - The PWA install prompt is misleading: users expect installed apps to work offline - No background sync for reconnection ### Recommendation 1. Implement a CacheStorage snapshot of critical IndexedDB data (people list, recent interactions) 2. Change navigation strategy to "cache-first, network refresh in background" for the app shell 3. Consider Workbox or a similar SW library for more robust caching patterns ### Code context - `public/sw.js` — full service worker
Author
Owner

GSD RESEARCH could not determine a clear fix.

STATUS: UNCLEAR
EVIDENCE: The sw.js has not been modified since the initial bootstrap (4 commits, all lint/format cleanup only). However, the issue itself is based on a technical misunderstanding that needs clarification before any fix can proceed.

Current sw.js (75 lines) does:

  • Cache-first for all same-origin GET requests (line 46: caches.match...cached || fetch)
  • Static asset precache (/, index.html, manifest.json, icons)
  • Runtime caching of JS/CSS/fonts/images
  • Navigation fallback to
GSD RESEARCH could not determine a clear fix. STATUS: UNCLEAR EVIDENCE: The sw.js has not been modified since the initial bootstrap (4 commits, all lint/format cleanup only). However, the issue itself is based on a technical misunderstanding that needs clarification before any fix can proceed. Current sw.js (75 lines) does: - Cache-first for all same-origin GET requests (line 46: `caches.match...cached || fetch`) - Static asset precache (/, index.html, manifest.json, icons) - Runtime caching of JS/CSS/fonts/images - Navigation fallback to
Mark closed this issue 2026-05-16 06:29:59 +00:00
Author
Owner

Fix deployed in 0b940d5

Analysis: IndexedDB (Dexie) persists data locally regardless of network state — the SW does not need to "cache" DB data. The app already auto-seeds sample data on first launch.

What was missing: user confidence. Added an OnlineStatus indicator in the sidebar bottom section showing:

  • Green dot + "Offline-ready" when online (data synced locally)
  • Amber dot + "Offline" when offline (data still available)

Not a PWA bug, but a UX gap — users need to know their data is available offline.

**Fix deployed in 0b940d5** Analysis: IndexedDB (Dexie) persists data locally regardless of network state — the SW does not need to "cache" DB data. The app already auto-seeds sample data on first launch. What was missing: user confidence. Added an `OnlineStatus` indicator in the sidebar bottom section showing: - **Green dot + "Offline-ready"** when online (data synced locally) - **Amber dot + "Offline"** when offline (data still available) Not a PWA bug, but a UX gap — users need to know their data is available offline.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/kimi_agent_kin_app_sync#9
No description provided.