mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
Kill the above-the-fold first-load flash on `/`: the hero digest and the batched chart series still fired client-side after JS download + hydrate, so the hero and charts painted empty and filled in seconds later (LCP ~5.5 s mobile-throttled while the snapshot already dehydrated). Extend the existing `page.tsx` snapshot prefetch to also seed the daily digest and the chart series batch into the same dehydrated TanStack cache, under keys byte-identical to the client's: - Extract the series-batch route core into `readSeriesBatch(...)` so the RSC and the route share one code path (no HTTP-to-self); the route thins to auth + Zod + the shared reader, behaviour unchanged. - New client-safe pure module `batch-chart-types.ts`: `deriveBatchChartTypes` (the single implementation of the visible-with-data type-set derivation, order + resting-HR-vs-pulse pick preserved) and `computeBatchWindow` (profile-tz end-of-day minus the coverage window). Server and client run the same function over the same snapshot payload, and the window is computed once server-side and threaded to the client as a prop, so the `chartSeriesBatch` key matches on both sides by construction. - Render the hero data-first so the SSR HTML carries the populated hero (the LCP element) — hydration-safe because the digest is dehydrated and never restored from the IndexedDB persist allowlist; bound that invariant with comments on both the hero gate and the allowlist. - Warm the shared chart-runtime chunk during hydration. Both prefetches honour the `DASHBOARD_SSR_PREFETCH=false` escape and fail soft to the client-fetch path on any error; a ~400 ms soft budget bounds the cold-day digest cost. No contract change, no visual change.