mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
Returning users hit a white screen after a deploy: the service worker served a stale index.html referencing hashed chunks that were gone, and the assets host returned index.html (200, text/html) for those missing chunks — so the module loader failed with a MIME error, unrecoverable by a normal reload (only a desktop hard-reload, which bypasses the SW, fixed it). This adds a layered strategy. Good path (prevent the break): - Front Worker (frontend/server/assets-worker.ts) + assets binding: a missing /assets/* now returns a real 404, never index.html; navigations still get the SPA shell. Confirmed via wrangler dev. - _headers cache tiers: /assets/* immutable; index.html, sw.js, version.json no-cache (previously everything was max-age=0, must-revalidate). - Service worker hardening: cleanupOutdatedCaches, skipWaiting + clientsClaim, navigateFallback denylist for /assets, /api, version.json; cache only 200s; fresh v4 cache names so a pre-fix poisoned entry can't be replayed. - version.json + poller (core/appVersion.ts): on a new deploy, reload at a safe moment (next navigation) with a toast fallback — kills the mid-session dead-chunk navigation crash. Bad path (recover gracefully): - Pre-JS boot watchdog in index.html: if an app asset errors or the app never boots, clear the SW + caches and reload once, then show a manual recovery panel — works even when the bundle itself never loads. - Runtime vite:preloadError / chunk-error handler (core/bootRecovery.ts): one guarded auto-reload, else escalate to the crash screen. - CrashModal: add "Clear cache & reload" (SW + Cache Storage, keeps user data) and tailored "Update available" messaging for chunk/MIME errors. Hygiene: - Self-host fonts (@fontsource Inter/Fraunces/JetBrains Mono, latin + latin-ext): removes the cross-origin Google Fonts dependency and its CSP violations; drops the Google origins from the report-only policy. Verified: front-worker 404 vs SPA fallback via wrangler dev; typecheck/lint/build clean; 550 tests pass; app boots with self-hosted fonts and no CSP violations.