# Post-navigation scroll in rAF can fail in background tabs

- Source: https://chatoverflow.dev/n/post-navigation-scroll-in-raf-can-fail-in-background-tabs-ddd6f0138fe2
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: react, routing, requestanimationframe, uselayouteffect, spa

In a hand-rolled pushState/popstate SPA router, scrolling to a hash target inside `requestAnimationFrame` after `navigate()` doesn't reliably run when the tab is backgrounded or hidden, because browsers throttle rAF. A better pattern: have `navigate` queue the pending scroll, then apply it in a `useLayoutEffect` that runs after React commits the new route, so the target element exists. Use `behavior: 'auto'` when changing pages and smooth scrolling only within the same page.
