fix: resolve pre-cache 404s and implement Bunker v7 with SWR

This commit is contained in:
2025-12-20 23:44:37 +01:00
parent b2c8ef222f
commit 7d5091a139
4 changed files with 81 additions and 93 deletions

View File

@@ -62,13 +62,15 @@ A critical feature is the ability to link tasting notes to a bottle that hasn't
## 📱 PWA Features
### Service Worker (`public/sw.js`) - "Paranoid Mode" Strategy
The Service Worker implements an extremely resilient "Cache-First, Network-Background" strategy for navigation:
### Service Worker (`public/sw.js`) - "Bunker v7 + SWR"
The Service Worker implements a robust "Cache-First, Network-Background" strategy:
- **Pre-Caching**: The landing page (`/`), core static assets, and the sessions overview (`/sessions`) are cached during installation.
- **SWR Navigation**: Navigation requests are handled with Stale-While-Revalidate. The SW serves the cached version immediately (instant load) and refreshes the cache in the background.
- **Universal Root 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 (including Scan and Note features) using local Dexie data.
- **RSC Data Resiliency**: Requests to `/_next/data/` return an empty JSON object if they fail, preventing "Application Error" screens.
- **Pre-Caching**: The landing page (`/`) and core static assets are cached individually during installation to prevent total failure on single-file 404s.
- **Manifest Path**: Corrected to `/manifest.webmanifest` to match Next.js defaults.
- **SWR Navigation & Assets**: Both load instantly from cache. Updates happen in the background via `fetchWithTimeout` and `AbortController`.
- **Universal Root Fallback**: Deep links (like `/bottles/[id]`) fallback to `/` if not cached, allowing Next.js to take over.
- **Network Stability**: Added a 2-second stabilization delay in `UploadQueue.tsx` before background sync starts after a network change.
- **RSC Data Resiliency**: Requests to `/_next/data/` return an empty JSON object if they fail.
- **Stale-While-Revalidate**: Applied to static assets to ensure immediate UI response.
### Manifest (`src/app/manifest.ts`)