An offline-capable PWA habit tracker styled as a hand-kept almanac. Built on Next 16 with the React Compiler, with a hand-written service worker (network-first for navigations, stale-while-revalidate for everything else) and a three-tier test suite that pins down auth, persistence, and offline rendering.
Service worker, hand-written
Three handlers and two strategies, all in one file. Install pre-caches the app shell. Activate purges the old cache version and claims clients. Fetch is the interesting part: navigations are network-first with a fall-back chain to the cached page, then the cached / shell, then a 503; everything else is stale-while-revalidate so the second visit is instant while the cache refreshes in the background.
Streak walk
Habit completions are a sorted-on-read set of YYYY-MM-DD strings. The streak calculator walks backwards from today, counting consecutive days that appear in the set; duplicates are deduped via new Set before the walk. Vitest pins the edge cases — no completions, today missing, breaks on the first gap, duplicates ignored — and Playwright validates the full toggle-and-render loop in a real browser.