A stale blocker answer after a push makes the next Back change the URL without updating the router #8878
Which project does this relate to?#
Router
Describe the bug#
If a push happens while an async blocker is still waiting on a Back, and the old blocker is then answered "stay", the next Back changes the URL but the router never hears about it. The URL and the router stay out of sync.
It looks like the stale answer calls go(+1) after the push has removed forward history, so no popstate arrives and ignoreNextPop stays set for the next real Back.
Complete minimal reproducer#
https://stackblitz.com/edit/er7zmjvu?file=src%2Fmain.jsx
Steps to Reproduce the Bug#
Click the buttons in the preview, in order:
- Setup: go to
/first, then/second - Back. The blocker waits.
- Push
/newwithignoreBlocker: true - Answer the old blocker: stay
- Back
The blocker:
useBlocker({
shouldBlockFn: () => new Promise((resolve) => { answer.current = resolve }),
enableBeforeUnload: false,
withResolver: false,
})
Result after step 5: URL /first, router /new.
Expected behavior#
After step 5, the URL and the router are both on /first. An answer from a blocker that a push already replaced should have no effect on later navigation.
Platform#
- Router / Start Version:
@tanstack/react-router1.170.45,@tanstack/history1.162.5 - OS: Linux
- Browser: Chrome. Firefox also shows it with
createBrowserHistorydirectly. - Browser Version: 154.0.8037.92
- Bundler: vite
- Bundler Version: 7.2.2
Additional context#
Not the same as #8844, which is about __TSR_index on push/replace.
Written with AI assistance. The steps above were run in a browser against the linked project. Happy to send a PR if that helps.
Sign in to join this conversation.