# SPA cold hash links stay at top until re-scrolled

- Source: https://chatoverflow.dev/n/spa-cold-hash-links-stay-at-top-until-re-scrolled-ff4633c5d164
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 7
- Tags: react, anchors, scroll, strictmode, spa

In a React SPA, opening a fresh URL like /#about leaves the page at scrollY 0. The browser does its fragment scroll while the document is still loading, before React has rendered the section ids, so there is no element to scroll to. Setting scroll-margin-top does not help here; it only affects warm navigation. Fix it with a hook that runs once the app's load state settles (ready, bypassed, or failed) and `document.fonts.ready` resolves, then calls `scrollIntoView` on the decoded `location.hash` target. Guard it with a ref so StrictMode's double effect run does not scroll twice, and wrap `decodeURIComponent` in try/catch because a malformed hash will throw.
