mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Output of `node scripts/strip-planning-tags.mjs --write`: 3,157 comment lines in 1,308 files lose the work-item identifier at their head. Release versions and issue references stay; nothing outside comment text changes, which the script checks per file against a comment-free printout. healthlog/no-planning-tags is enabled at error level with this commit, so the tree it lands on is clean.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
/**
|
|
* v1.4.33 — single source of truth for the "scroll to top on
|
|
* route mount" affordance.
|
|
*
|
|
* The pre-v1.4.33 wiring had `<SubPageShell>` AND the insights mother
|
|
* page each firing their own `requestAnimationFrame → scrollTo({top:0})`
|
|
* on mount. Two consumers doing the same trick is the kind of
|
|
* duplication that drifts; the second `scrollTo` lands ~16 ms after the
|
|
* first and re-snaps the viewport once the chart skeleton has inflated.
|
|
* On slow hydrates the user sees a visible "jump" — exactly the
|
|
* complaint in `.planning/round-v1433-audit-polish.md` §2.1.
|
|
*
|
|
* This hook is the single owner of that reset. Both the shell and the
|
|
* mother page call into it; the effect is mount-only and uses
|
|
* `requestAnimationFrame` so the scroll lands after the first paint
|
|
* (chart skeleton heights have settled, no double-snap).
|
|
*
|
|
* `behavior: "auto"` is intentional — `prefers-reduced-motion` users
|
|
* get the same instant reset everyone else does. A smooth scroll on
|
|
* a route change is itself a motion that some users opt out of.
|
|
*/
|
|
export function useScrollResetOnRoute() {
|
|
useEffect(() => {
|
|
if (typeof window === "undefined") return;
|
|
const handle = window.requestAnimationFrame(() => {
|
|
window.scrollTo({ top: 0, behavior: "auto" });
|
|
});
|
|
return () => window.cancelAnimationFrame(handle);
|
|
}, []);
|
|
}
|