Our Site Crashed Only in Safari: The history.replaceState Limit Nobody Tells You About
This happened on our own site in November 2026. Chrome and Firefox were fine. A colleague scrolled our homepage in Safari, the page went black, and Next.js showed its "Application error: a client-side exception has occurred" screen. She sent a 9-second screen recording. The answer was in the Web Inspector console in the corner of the video.
What the code did
The homepage updates the URL hash as you scroll, so or appears in the address bar when that section reaches the middle of the screen. The handler looked reasonable at first glance:
js const handleScroll = () => { if (ticking) return; ticking = true; requestAnimationFrame(() => { for (const section of document.querySelectorAll('section[id]')) { const top = section.getBoundingClientRect().top; if (top >= 0 && top <= window.innerHeight / 2) { window.history.replaceState(null, '', ); break; } } ticking = false; }); };
The throttle limits the work to one run per frame. One run per frame still means up to 60 calls a second, and the code called it even when the hash had not changed. Safari's limit is 100 calls in 10 seconds. A two-second scroll was enough.
Next.js App Router also patches to keep its own router state in sync. The exception escaped from inside that patched call, so React never got a chance to recover and the whole page unmounted.
The fix
Two rules: only call when the hash actually changes, and never more than once every 300 ms.
js const MIN_INTERVAL_MS = 300; let lastHash = window.location.hash; let lastUpdate = 0; let pending = null;
function updateHash(hash) { if (hash === lastHash) return; const wait = MIN_INTERVAL_MS - (Date.now() - lastUpdate); if (wait > 0) { clearTimeout(pending); pending = setTimeout(() => updateHash(hash), wait); return; } try { window.history.replaceState(window.history.state, '', hash); lastHash = hash; lastUpdate = Date.now(); } catch { // Rate-limited by the browser. Skip this update. } }
Two details matter here:
- Pass instead of . Next.js stores router data in that state object, and wiping it can break back-button behaviour.
- The is a safety net, not the fix. The dedupe and the interval are what keep you under the limit.
We simulated 10 seconds of fast scrolling across eight sections. The old handler made 84 calls; real momentum scrolling in Safari goes well past 100. The new one made 7, one per section change.
Where else this bites
Any code that writes to the URL in a loop can hit the same wall:
- Scroll-spy navigation that syncs the active section into the hash.
- Search inputs that push every keystroke into .
- Map or chart components that store zoom and position in the query string on every move.
- Infinite lists that update as you scroll.
The same pattern fixes all of them: compare before you write, and debounce. For search inputs, update the URL on a 300-500 ms debounce or on submit.
Why nobody noticed
Our site had no error monitoring in the browser. The crash only happened in Safari, only on a fast scroll, and only on pages with the scroll handler. Nobody on the team uses Safari as their main browser. Without a colleague who happened to try it, we would have kept losing every Safari visitor who scrolled quickly.
The same week we added Sentry to the site. Three days later it caught a different production error that nobody had reported. We wrote that up separately: .
Checklist
- Search your codebase for and .
- For each call, check whether it can run more than a few times a second.
- Add a "did the value change" check before the call.
- Debounce or throttle to 300 ms or more.
- Test in Safari with a fast trackpad scroll, with the console open.
- Add browser error monitoring so the next one reaches you before a user does.
If your app crashes for some users and you cannot reproduce it, that is the kind of problem our starts with.
FAQ
What services do we provide?
We specialize in creating innovative digital solutions including web development, mobile applications, CRM systems, and enterprise software. Our services are tailored to meet your specific business needs and drive growth.

Oleksii Stupak
CEO @ AleannLab
"Want to explore how we can help your business grow? Let's connect and discuss your project on LinkedIn."
Ready to discuss your project with us?




