feat(frontend): offline support via service worker#516
Conversation
Precache the app shell and serve cached data when the network is unavailable: - gameplan-sw.js: service worker that precaches built assets listed in a build-time manifest and serves them offline. - vite.config.ts: offlineAssetManifest() plugin emits gameplan-offline-assets.json (CSS/JS/font URLs) at build time. - offline.ts: registers the service worker and exposes isBrowserOffline() / isNetworkError() helpers. - data layer: add staleOnError + cacheKey to useList/useDoc so cached responses are served on network failure. - router.ts: hydrate community/space data from cache and skip route validation (NotFound) when offline or on network errors.
Confidence Score: 4/5The offline shell caching path needs a fix before merging.
gameplan/www/gameplan-sw.js, frontend/src/data/users.ts, frontend/src/router.ts
|
| try { | ||
| const response = await fetch(request); | ||
| if (isHtmlResponse(response)) { | ||
| await cache.put(APP_SHELL_URL, response.clone()); |
There was a problem hiding this comment.
Shared Shell Stores Session Data
This stores every navigation response as the single /g shell, but the /g page is rendered with per-request boot data such as the CSRF token. If one user populates the service-worker cache and another user later opens the app from the same browser profile while offline or after a navigation fetch failure, the app can boot with the previous user's HTML and stale CSRF data, causing wrong session state or failed API writes.
| cacheKey: 'Users', | ||
| staleOnError: true, |
There was a problem hiding this comment.
This stale-on-error cache is keyed only as Users, so a same-tab account switch can reuse the previous account's user list when the next fetch fails. The UI can then show another account's people, roles, or profile metadata instead of failing closed for the current session.
| if (isRouteValidationUnavailable()) { | ||
| communityState.scope(communityId) | ||
| return | ||
| } |
There was a problem hiding this comment.
Missing Space Proceeds Offline
When route validation is unavailable, this branch scopes the requested community and lets navigation continue even though getSpace() returned nothing. A deep link to an uncached or deleted space while offline can render the matched route without a valid space instead of showing NotFound, leaving page components to operate on missing route state.
UI Test Results✅ All passed — 42/42 tests passed in 2m 50s.
Results for commit 01e55fc. |
What
Adds offline support to the Gameplan SPA so the app shell loads and cached data is served when the network is unavailable.
How
gameplan/www/gameplan-sw.js) precaches built assets listed in a build-time manifest and serves them when offline.offlineAssetManifest()invite.config.ts) emitsgameplan-offline-assets.json(CSS/JS/font URLs) at build time.offline.tsregisters the service worker and exposesisBrowserOffline()/isNetworkError()helpers.staleOnError+cacheKeyadded touseList/useDoccalls so cached responses are served on network failure.NotFoundroute validation when offline or on network errors.Notes
Frontend-only behavior change plus one new backend static file (the service worker). No schema or API changes.