history: push/replace stamp __TSR_index before blockers are awaited, so a second navigation gets the wrong index (canGoBack() returns false)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
The eager index stamp is in createHistory's push and replace, using assignKeyAndIndex with currentIndex + 1 before tryNavigation awaits the blockers; location is only updated in the task's notify. Start by reproducing with the minimal script in the issue against memory history, then move the __TSR_index computation into the task so it reads location.state at write time. Done when push then replace, and push then push, leave the correct indices and canGoBack() returns true, with blockers still receiving the eager nextLocation.
索引モデルが issue の本文から書いたものです。
説明
Which project does this relate to?
Router
Describe the bug
createHistory's push and replace compute the new entry's __TSR_index from location at the moment they are called (assignKeyAndIndex(currentIndex + 1, state)), and only afterwards await the registered blockers in tryNavigation. location itself is only updated inside the task's notify.
So with any blocker registered (even one that always returns false), a second navigation made while the first is still waiting on its blockers is stamped from the entry before the first one:
pushthenreplacein one click lands a single entry carrying the previous entry's index, sohistory.canGoBack()returnsfalseon a page you can go back from (a "Back" control reading it shows disabled).pushthenpushstamps both entries with the same index.
Any app with an always-on useBlocker (for example an unsaved-changes guard) hits this on every click that makes two navigations.
Complete minimal reproducer
// @tanstack/history 1.162.4 (react-router 1.170.40). Blockers only run where a `document` exists.
globalThis.document ??= {};
const { createMemoryHistory } = await import("@tanstack/history");
const history = createMemoryHistory({ initialEntries: ["/list"] });
history.block({ blockerFn: async () => false, enableBeforeUnload: false });
history.push("/record");
history.replace("/record/letters");
await new Promise((r) => setTimeout(r, 0));
console.log(history.location.pathname, history.location.state.__TSR_index, history.canGoBack());
// actual: /record/letters 0 false
// expected: /record/letters 1 true
Steps to Reproduce the Bug
- Register any blocker on the history (
history.block({ blockerFn: async () => false }), oruseBlockerin an app). - In one synchronous handler, call
push(a)and thenreplace(b)(orpush(b)). - Read
history.location.state.__TSR_index/history.canGoBack()after both land.
Expected behavior
The index is stamped inside the task, from location at write time (push: location.state.__TSR_index + 1; replace: location.state.__TSR_index), so each entry is numbered from the entry it actually follows. The eagerly stamped state can still be used for the blockers' nextLocation.
Platform
- @tanstack/history 1.162.4, @tanstack/react-router 1.170.40
- Reproduces in Node (memory history) and in the browser (browser history)
Additional context
Related but not the same: #3193. Without a blocker the bug doesn't show, because the navigations land synchronously and location is current when the second one is stamped.
- 主要言語
- TypeScript
- スター
- 15.3k
- フォーク
- 1.9k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 46
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/router のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')対応中かも @hassanabrar202 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)対応中かも @Sheraff が 27 日前に担当しました。 オープンpackage: router-generator performance
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiers対応中かも @Sheraff が 27 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
docs(router): clarify static title fallback in SPA mode対応中かも @Rohan-Dedhia が 17 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
TanStack/router の issue をすべて見る
似ている issue
-
[BUG]: Shared links drop the configured basePath on GitHub Pages対応中かも @anshulchikhale30-p が今日担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add: GTrekkerオープンcheck:passed streams:add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
メンテナーはふだん 1 日以内に返信
-
area: ui Bug Payload OSS
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
payloadcms/payload#19839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
メンテナーはふだん 1 日以内に返信