PWA & offline reading
Rendered from corpus/wiki/pwa.md · updated 2026-11-02
This page is generated from the project corpus and rewritten on every docs build. Edit the source in corpus/, not here.
Shipped 2026-07-16 (2026-07-16). The app is installable, the shell loads from a service-worker cache, and explicitly-downloaded books are fully readable with zero connectivity.
Shell (2026-07-16)
vite-plugin-pwa(generateSW — declarative Workbox, no sourcesw.ts), configured entirely in vite.config.ts. Anything needing custom SW fetch logic later must migrate toinjectManifest; offline books deliberately did NOT need that (they're read app-side from IndexedDB, not intercepted in the SW).- Manifest colors are the one allowed raw-hex site (
#fcf9f8=--paper). Icons inapps/web/public/(192/512/maskable/apple-touch). - Precache includes the pdf.js worker (
mjsin globPatterns — the reader must work offline). 35 entries / ~3047 KiB as of the Reading Room rework. woffis deliberately absent fromglobPatterns(D33 work):@fontsourceships a.wofffallback beside every.woff2, and precaching both spent ~299 KiB on a format no browser that can run this app will request. The files are still built and served, just not precached.- Updates are prompt-mode:
registerType: "prompt",injectRegister: false, UpdateToast.tsx (useRegisterSW) mounted in the root layout outside the auth gate. Never addskipWaiting/clientsClaim— no silent swap mid-read. - Runtime caching: cover thumbnails only (stale-while-revalidate, 200
entries), pattern derived from the
VITE_API_URLorigin (cover URLs drop any base path — seecoverUrl). No other API caching; auth/freshness stay server-driven. scope/start_url/navigateFallbackall derive fromBASE_PATH(normalized to a trailing slash). Verified against a non-root base.
Offline reading (2026-07-16)
Locked product decisions: explicit per-book download (no auto-cache), IndexedDB storage, last-write-wins progress sync (no mutation queue), cached content readable offline without re-auth, upload/delete online-only.
- offline-store.ts: typed IndexedDB
wrapper, DB
ebook-reader:offlinev2, three stores —books(metadata snapshot, no blob),files(id → blob),progress({fraction, locator, updatedAt, syncedAt}). The blob/metadata split is load-bearing: snapshot refreshes and listings must never deserialize or rewrite blobs (a v1 single-store design thrashed ~100s of MB per Home visit). v1→v2 upgrade migrates blobs in the versionchange transaction. - Open path:
useHydrateBookchecks the offline store first (even online); miss → network as before. Reader renderers unchanged — they still consume an in-memoryFile. - Library:
useLibraryListserves cached rows +isOfflinewhenGET /libraryfails;useOfflineDownloadpowers the cover toggle (OfflineToggle.tsx, top-left on the card), the storage caption inLibraryHeader, and remove. - Progress: every debounced sync tick also writes the local row;
useReconnectProgressSync(mounted once on Home) flushes pending rows (updatedAt > syncedAt) once on start/online— guarded by an in-flight latch and identity-stable row arrays (review caught a live 3×-duplicate-PATCH bug from unstable references; fixed and re-verified at exactly 1 PATCH). Resume prefers a pending local row so a snapshot refresh can't shadow an offline reading position. The wireLibraryBookhas no per-user progress timestamp, so pending-ness is local-only — revisit if the API ever returnsupdated_at.
Known edges
- With zero downloads, going offline shows the plain error state (there's
nothing cached to fall back to) —
isOfflineonly flips when cached rows exist. - Deploy prerequisite: service workers require HTTPS in production.
- E2E evidence (2026-07-16, real browser): download → offline reload → banner + downloaded covers → EPUB opens/pages/resumes at exact CFI → PDF opens → reconnect PATCHes exactly once; v1→v2 migration exercised against a live profile; update toast exercised across a real rebuild.