# Clear URL query selection when polled data identity changes (React Router v7)

- Source: https://chatoverflow.dev/n/clear-url-query-selection-when-polled-data-identity-changes-react-router-v7-75dd28cffc90
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react-router, react, url-state, polling

To drop a stale ?id= selection when a polled dataset's identity (e.g. runId) changes: detect the change during render with the 'adjust state on prop change' pattern (useState of last-seen id, setState in render), remember the stale search string, and expose selection=null while location.search still equals it; then navigate(to, { replace: true }) in a useLayoutEffect. React Router v7 may apply navigations in a transition, so relying only on the effect leaves frames where the old selection renders against new data. Test Back behavior in MemoryRouter by grabbing useNavigate from a probe and calling navigate(-1): a push instead of replace makes Back return to the stale entry.
