feat(offline): installable PWA dashboard — service worker, background sync & offline mutations - #663
Open
micmusjnr20 wants to merge 2 commits into
Open
feat(offline): installable PWA dashboard — service worker, background sync & offline mutations#663micmusjnr20 wants to merge 2 commits into
micmusjnr20 wants to merge 2 commits into
Conversation
…WA install Adds a Workbox service worker that precaches the app shell and serves GET API list endpoints stale-while-revalidate, an API-reachability-aware offline banner, background sync for payment links and webhook tests created while offline, and a web manifest with icons plus an install prompt for the merchant dashboard. Verified end-to-end with `npm run verify:offline` (13/13 checks: the shell renders offline with cached data and the banner; an offline-created payment link is replayed on reconnect and appears in the list). `npm run build` passes; jest shows only pre-existing failures. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
…ified feat(offline): installable PWA dashboard — service worker, background sync & offline mutations
|
@micmusjnr20 is attempting to deploy a commit to the therealjhay's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #467
Summary
The merchant dashboard was fully network-dependent: no offline shell, no cached assets, and every mutation failed the moment connectivity dropped. This PR turns the dashboard into a resilient, installable PWA:
scripts/sw-template.jsis bundled byscripts/build-sw.mjs(rollup + workbox-build, wired intonpm run build) intopublic/sw.js. It precaches the Next.js app shell (JS/CSS/fonts/icons), serves navigations network-first with a cached-shell fallback per route, and runtime-caches GET API list/detail responses stale-while-revalidate (same-origin/api/*and theNEXT_PUBLIC_API_URLorigin), so list pages stay populated offline.offlineStore+useOnlineStatus: the banner reflects API reachability (healthz poll), not justnavigator.onLine, and also shows how many offline changes are waiting to sync./healthzis never cached, so reachability is always live.lib/offline/syncQueue.ts, shared with the SW) and replayed automatically when connectivity returns (nativesync+ SWonlineevent + client-side reconnect trigger). The payments page shows a pending-sync badge and refetches onSYNC_COMPLETE; the webhook tester marks queued deliveries "Queued (offline)" and flips them to delivered/failed after replay.public/manifest.webmanifest+ generated icons (scripts/generate-icons.mjs) +components/layout/InstallPrompt.tsxcapturebeforeinstallpromptso merchants can install the dashboard. The middleware matcher now excludessw.js, the manifest, and icons so they're never redirected to login.How it works (walkthrough)
Verification
npm run verify:offlinedrives a production build in headless Chromium through the full scenario — 13/13 checks passed on this branch:npm run buildpasses (451 precached assets, ~15.7 MiB shell).npm run typecheck: no new errors — remaining errors are pre-existing implicit-any in unrelated test files (lib/status/__tests__/time.test.ts).lib/offlinetests pass; the only failing suites are the same pre-existing ones that fail onmain.mainin this environment — no new regressions.Notes for reviewers
components/ui/service-worker-registration.tsx) so dev HMR is unaffected.public/sw.jsis build-generated and git-ignored — it embeds the build-timeNEXT_PUBLIC_API_URLso the SW matches the same API origin the client uses.lib/api/axios.ts); they pass through so the SW can answer from cache. Mutations still fail fast so callers can queue them for background sync.networkMode: 'offlineFirst'so they reach the SW when the browser reports offline.CLEAR_API_CACHE) so a different account never sees stale session/payment data.lib/api/hooks.ts(missingisFetching) that blockednext build.Test plan
npm run build— passes.NEXT_PUBLIC_API_URL=http://localhost:3000 npm run build && npm run verify:offline— 13/13 checks./dashboard— shell + data render with banner; create a payment link offline; reconnect — it syncs and appears in the list.Supersedes
feat/offline-merchant-dashboard)feat/offline-merchant-dashboard-v2)Same change, re-verified end-to-end on this branch.