You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
createBrowserHistory discards existing History and Navigation API entry state during initialization #8735
createBrowserHistory() adds its initial key by calling history.replaceState with a new object. When the entry has neither key nor __TSR_key, this drops existing application fields, resets an existing __TSR_index, and clears the independent Navigation API entry state. No navigation is necessary to trigger it.
Verified with unmodified @tanstack/history@1.162.4 in Chromium 151.0.7922.34. The same reproduction fails with public source commit 18154b1c45454a70aa77e9d6d27c8a6e0733d031.
All three synthetic cases (null, false, and an object Navigation API state) report preserved: false. After initialization, History state contains only the generated keys and __TSR_index: 0. Navigation entry state is undefined.
git clone https://gist.github.com/5ea3f094b7d1d981f753bf4868ba27ec.git history-initialization-repro
cd history-initialization-repro
npm install
npm start
Open http://127.0.0.1:8000 in a browser supporting the Navigation API.
Observe all three cases print preserved: false.
The two-file example uses only the pinned public History package and Node's built-in HTTP server. Each case sets { color: "blue", __TSR_index: 7 }, sets independent Navigation API state, constructs browser History, and reads both states immediately afterward.
Expected behavior
Initialization should add the router's keys while preserving the existing color field, index 7, and independent Navigation API entry state, including null and false. All three cases should print preserved: true.
The initialization branch in packages/history/src/index.ts should retain the existing History state and use its existing index when present. Native replaceState also clears Navigation API state, so snapshot that independent state before the call and restore it with navigation.updateCurrentEntry when it is not undefined. A truthiness check would incorrectly drop null and false.
Applying those changes to the 1.162.4 source makes all three browser cases report preserved: true. Already-keyed entries need no extra initialization mutation.
This is distinct from #3907 / #8724, which address missing indexes on entries that already have a router key.
I'll open a PR for this: keep the existing state fields and __TSR_index when adding the initial key, and restore the Navigation API entry state after replaceState when it isn't undefined, with unit tests.
Activity
AmineBenzaazaa commentedon Oct 17, 2026
I'll open a PR for this: keep the existing state fields and
__TSR_indexwhen adding the initial key, and restore the Navigation API entry state afterreplaceStatewhen it isn'tundefined, with unit tests.