diff --git a/OFFLINE_SYNC_PWA.md b/OFFLINE_SYNC_PWA.md index f9f5b7e..075104b 100644 --- a/OFFLINE_SYNC_PWA.md +++ b/OFFLINE_SYNC_PWA.md @@ -62,13 +62,14 @@ A critical feature is the ability to link tasting notes to a bottle that hasn't ## 📱 PWA Features -### Service Worker (`public/sw.js`) -- **Strategy**: Network-First. Attempts to fetch from network, falls back to cache if offline. -- **Cache Bypassing**: Explicitly bypasses cache for: - - `*/auth/*` - - `*/api/*` - - `*.supabase.co/*` -- **Asset Caching**: Caches static assets (`manifest.json`, icons) during installation. +### Service Worker (`public/sw.js`) - "Ironclad" Strategy +The Service Worker implements an aggressive offline reliability strategy: + +- **Pre-Caching**: The landing page (`/`) and core static assets are cached during installation. +- **Fail-Fast Navigation**: Navigation requests have a 3-second timeout to prevent UI hangs during network transitions. +- **Root App Shell Fallback**: If a URL is not found in the cache while offline, the SW serves the Root (`/`). This allows Next.js to bootstrap and handle the routing client-side using local Dexie data. +- **RSC Data Resiliency**: Requests to `/_next/data/` return an empty JSON object if they fail, preventing "Application Error" screens. +- **Stale-While-Revalidate**: Applied to static assets to ensure immediate UI response. ### Manifest (`src/app/manifest.ts`) Defines the app's appearance when installed: @@ -83,9 +84,10 @@ Defines the app's appearance when installed: - `src/lib/db.ts`: Database definition and TypeScript interfaces. - `src/hooks/useBottleData.ts`: Example of the SWR pattern implementation. - `src/components/UploadQueue.tsx`: The "Sync Engine" UI and logic coordinator. +- `src/components/CameraCapture.tsx`: Integrated scanning feature. +- `src/components/TastingNoteForm.tsx`: Integrated tasting note feature. - `src/components/PWARegistration.tsx`: Client-side Service Worker registration handler. ## ⚠️ Edge Case Handling - **Partial Sync**: If a scan succeeds but a tasting fails, the tasting remains in the queue with the now-valid `bottle_id`. -- **Duplicate Scans**: The system relies on the user not submitting the same scan multiple times while offline (UI prevents multiple clicks). - **Stale Cache**: Caches are overwritten on every successful online fetch to ensure eventual consistency. diff --git a/public/sw.js b/public/sw.js index 26f2401..ba48d98 100644 --- a/public/sw.js +++ b/public/sw.js @@ -2,9 +2,7 @@ const CACHE_NAME = 'whisky-vault-v4'; // Increment version for "Ironclad" strate // CONFIG: Core pages and assets to pre-cache immediately on install const CORE_PAGES = [ - '/', // Dashboard / Home - '/tasting/new', // Critical: Add Tasting Screen - '/scan', // Critical: Scan Screen + '/', // Dashboard / Home (Includes Scan and Tasting features) ]; const STATIC_ASSETS = [