Add offline-first sync queue and harden PWA boot#14
Draft
hsalaman1 wants to merge 1 commit into
Draft
Conversation
Make the app stay usable when the network is unavailable so observations are never lost. Adds a localStorage-backed sync queue that holds submissions while offline and drains them automatically when connectivity returns; adds a root ErrorBoundary so a hook failure no longer blanks the screen; bumps the Workbox precache cap so the pdfmake/docx bundles ship with the service worker; and surfaces the offline state, pending count, manual Sync, and per-item retry/ discard controls in the existing export bar. https://claude.ai/code/session_017dxUBBwJ41917z2m6Z4ePp
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Reported issue: the app appears to "shut down" (blank screen) when there is no internet, especially on first launch. Two real causes were found:
ErrorBoundaryanywhere — any uncaught hook/render error produced a blank screen.maximumFileSizeToCacheInByteswas 5 MB, which silently dropped the pdfmake/docx bundles and left users with no signal that the app had cached for offline use.This PR makes the form fully usable offline, queues submissions locally, and auto-syncs when connectivity returns.
What changed
ErrorBoundary(src/components/UI/ErrorBoundary.jsx, wired insrc/main.jsx) renders a recoverable fallback with Reload / Copy details so a hook failure never blanks the UI again.vite.config.js):maximumFileSizeToCacheInBytesbumped to 10 MB so the heavy export bundles are precached, pluscleanupOutdatedCaches,navigateFallbackDenylist, and explicitdevOptions: { enabled: false }.src/main.jsxlistens ononOfflineReady, fires anapp:offline-readyevent, and persists a sticky flag. Newsrc/hooks/usePwaStatus.jsexposes that to the UI as an "Offline-ready" pill in the bottom bar.src/lib/submitObservation.js) factored out ofsrc/hooks/useSupabase.jsso both the direct submit and the sync queue use one code path.src/hooks/useSyncQueue.js):observation-sync-queue), one item per offline submission.useConnectivityreportssupabaseReachableand on the rawonlineevent (debounced 500 ms).queued | syncing | synced | error); errors don't block the rest of the queue.enqueue / flushQueue / retryItem / retryAll / removeItemAPI.src/App.jsx) is now offline-aware: online → direct submit (andresetObservation()on first insert), offline or server failure → enqueue and reset so the user can keep going.src/components/Export/ExportButtons.jsx):Honest constraint (called out in README)
A pure web PWA cannot load on a brand-new device that has never had internet — the browser must fetch the page at least once. After that single online visit the service worker caches everything and the app launches offline forever. Wrapping with Capacitor/Tauri is the only path to true zero-internet-first-launch and is out of scope for this PR.
Test plan
npm run build && npm run preview. Open once online; confirm the green Offline-ready pill appears in the bottom bar.synced, "All 2 reports synced." banner appears, badge clears.error; remaining queued items stay queued. Disable Offline and click Sync — remaining items succeed; errored item is retryable.throwin a child component to confirm the ErrorBoundary fallback renders instead of a blank screen, then revert.https://claude.ai/code/session_017dxUBBwJ41917z2m6Z4ePp
Generated by Claude Code