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

Closed
opened 2026-10-15 00:03:34 +00:00 by yuris · 0 comments
Owner

This was generated by AI during triage.

Problem Statement

As specified in docs/ARCHITECTURE.md §4.3, field inspectors and disaster response teams (Manggala Agni / BPBD) frequently operate in rural peatland concessions with intermittent or absent cellular network coverage.
Currently, public/sw.js does not exist. All PMTiles vector tile chunks and telemetry requests require active network connectivity. If connection drops, tile requests fail with unhandled fetch errors and the map canvas goes blank.

Technical Specification

  1. Service Worker Implementation (public/sw.js):
    • Register the service worker upon dashboard load.
    • Intercept /tiles/*.pmtiles and /api/tiles/* HTTP range requests (Range: bytes=X-Y).
    • Use CacheStorage with composite cache keys (url + ":" + rangeHeader).
    • If chunk is cached: return immediate synthetic HTTP 206 Partial Content response (Content-Range, Content-Length, Content-Type: application/x-protobuf).
    • If absent: fetch from network, clone response chunk into cache, and stream to MapLibre.
  2. Offline Fallback for Telemetry:
    • Cache last-known /api/hotspots, /api/tmat, and /api/health snapshots with network-first, cache-fallback strategy.
  3. Registration & Lifecycle:
    • Hook service worker registration in src/components/dashboard/dashboard-client.tsx or src/app/layout.tsx.

Acceptance Criteria

  • public/sw.js created and registered cleanly on client boot.
  • HTTP 206 range requests for .pmtiles are cached and served offline with 0ms latency.
  • Unit/integration tests verify service worker caching and synthetic 206 response creation.
  • pnpm exec vp check, pnpm test, and pnpm build pass with zero errors.
> *This was generated by AI during triage.* ## Problem Statement As specified in `docs/ARCHITECTURE.md §4.3`, field inspectors and disaster response teams (Manggala Agni / BPBD) frequently operate in rural peatland concessions with intermittent or absent cellular network coverage. Currently, `public/sw.js` does not exist. All PMTiles vector tile chunks and telemetry requests require active network connectivity. If connection drops, tile requests fail with unhandled fetch errors and the map canvas goes blank. ## Technical Specification 1. **Service Worker Implementation (`public/sw.js`)**: - Register the service worker upon dashboard load. - Intercept `/tiles/*.pmtiles` and `/api/tiles/*` HTTP range requests (`Range: bytes=X-Y`). - Use `CacheStorage` with composite cache keys (`url + ":" + rangeHeader`). - If chunk is cached: return immediate synthetic `HTTP 206 Partial Content` response (`Content-Range`, `Content-Length`, `Content-Type: application/x-protobuf`). - If absent: fetch from network, clone response chunk into cache, and stream to MapLibre. 2. **Offline Fallback for Telemetry**: - Cache last-known `/api/hotspots`, `/api/tmat`, and `/api/health` snapshots with network-first, cache-fallback strategy. 3. **Registration & Lifecycle**: - Hook service worker registration in `src/components/dashboard/dashboard-client.tsx` or `src/app/layout.tsx`. ## Acceptance Criteria - [x] `public/sw.js` created and registered cleanly on client boot. - [x] HTTP 206 range requests for `.pmtiles` are cached and served offline with 0ms latency. - [x] Unit/integration tests verify service worker caching and synthetic 206 response creation. - [x] `pnpm exec vp check`, `pnpm test`, and `pnpm build` pass with zero errors.
yuris closed this issue 2026-10-15 01:20:48 +00:00
Sign in to join this conversation.
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#95
No description provided.