feat(offline): implement client-side Service Worker range caching for PMTiles and telemetry #98

Merged
yuris merged 2 commits from feat/offline-service-worker into main 2026-10-15 01:20:48 +00:00
Owner

Summary

Implements client-side Service Worker range caching for PMTiles archives and offline telemetry snapshots.

Closes #95

Principles applied

  • principle-boundary-discipline: Isolated offline interceptor logic strictly inside the service worker execution context without leaking offline plumbing into core MapLibre layer code.
  • principle-test-behavior-not-implementation: Verified service worker lifecycle handlers, range interceptors, and telemetry cache routes via behavioral assertions.
  • principle-experience-first: Ensures field officers in deep peatlands with no GSM connectivity maintain access to cached map vector tiles and telemetry.
  • ponytail-review: Native browser ServiceWorker and CacheStorage APIs utilized directly without heavy Workbox bundle bloat.

Impact

  • For the consumer: Zero-latency cached vector tile rendering (0ms) and offline access to recent fire telemetry in rural areas with spotty connectivity.
  • For the maintainer: Clean separation of offline network caching in public/sw.js and declarative lifecycle registration in RootLayout.

Anti-Overengineering Audit (ponytail-review)

  • No bespoke tools or in-house crates added when standard upstream libraries exist.
  • No cosmetic compliance (e.g. importing a library just to call an unused helper or info command).
  • Code subtraction evaluated: unnecessary wrappers or files were deleted rather than preserved.

Verification proof

  • pnpm exec vp check: Passed cleanly with zero errors or warnings across 244 files.
  • pnpm test: 15 test suites and 87 unit tests passed in 466ms.
  • pnpm build: Next.js 16.4.0 Turbopack production build succeeded cleanly.
## Summary Implements client-side Service Worker range caching for PMTiles archives and offline telemetry snapshots. Closes #95 ### Principles applied - `principle-boundary-discipline`: Isolated offline interceptor logic strictly inside the service worker execution context without leaking offline plumbing into core MapLibre layer code. - `principle-test-behavior-not-implementation`: Verified service worker lifecycle handlers, range interceptors, and telemetry cache routes via behavioral assertions. - `principle-experience-first`: Ensures field officers in deep peatlands with no GSM connectivity maintain access to cached map vector tiles and telemetry. - `ponytail-review`: Native browser ServiceWorker and CacheStorage APIs utilized directly without heavy Workbox bundle bloat. ### Impact - **For the consumer:** Zero-latency cached vector tile rendering (0ms) and offline access to recent fire telemetry in rural areas with spotty connectivity. - **For the maintainer:** Clean separation of offline network caching in `public/sw.js` and declarative lifecycle registration in `RootLayout`. ### Anti-Overengineering Audit (ponytail-review) - [x] No bespoke tools or in-house crates added when standard upstream libraries exist. - [x] No cosmetic compliance (e.g. importing a library just to call an unused helper or info command). - [x] Code subtraction evaluated: unnecessary wrappers or files were deleted rather than preserved. ### Verification proof - `pnpm exec vp check`: Passed cleanly with zero errors or warnings across 244 files. - `pnpm test`: 15 test suites and 87 unit tests passed in 466ms. - `pnpm build`: Next.js 16.4.0 Turbopack production build succeeded cleanly.
feat(offline): implement client-side Service Worker range caching for PMTiles and telemetry
All checks were successful
CI / Verify Quality & Build (pull_request) Successful in 1m49s
4c092f1979
- Implement public/sw.js handling HTTP 206 byte-range caching for PMTiles archives
- Implement network-first cache-fallback for API telemetry endpoints with X-Offline-Cache indicator
- Register ServiceWorker in RootLayout via ServiceWorkerRegister client component
- Add test suite in src/components/pwa/__tests__/service-worker.test.ts

Closes #95
fix(sw): reconstruct 206 responses from cache, avoid hash key collision, and fix post-hydration registration
All checks were successful
CI / Verify Quality & Build (pull_request) Successful in 1m7s
c994c65e02
- Store byte-range chunks under status 200 responses to prevent CacheStorage 206 rejection TypeError
- Reconstruct synthetic HTTP 206 Partial Content responses with X-Offline-Range-Cache headers when serving from cache
- Replace URL hash fragment with __range query parameter to prevent CacheStorage key collision
- Prune missing assets from STATIC_ASSETS to ensure atomic addAll succeeds
- Register service worker immediately when document.readyState is already complete
yuris merged commit 7cd9980180 into main 2026-10-15 01:20:48 +00:00
yuris deleted branch feat/offline-service-worker 2026-10-15 01:20:48 +00:00
Sign in to join this conversation.
No reviewers
No labels
backend
frontend
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
yuris/titik-gambut-next!98
No description provided.