createBrowserHistory: one throwing pushState freezes the address bar for the rest of the session
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
Read packages/history/src/index.ts at the flush implementation identified in the issue, then inspect tests/createBrowserHistory.test.ts for related coverage. Reproduce a one-time throwing pushState and check how queued actions and subscriber notifications are reset. Done when a failed write affects only that navigation and a later navigation updates the URL; add a regression test for that behavior.
索引モデルが issue の本文から書いたものです。
説明
Which project does this relate to?
Router
Describe the bug
If the browser's history.pushState / replaceState throws a single time inside createBrowserHistory's flush, the address bar stops updating until a full reload (the router never calls history.flush() itself). The router keeps navigating (content and router.latestLocation change), but the URL stays on the old one.
The cause is in flush (packages/history/src/index.ts#L368-L389). next is cleared only after the browser call. When that call throws, next stays set. From then on every queueHistoryAction sees hasPendingAction === true and never queues flush again, so no later navigation reaches the browser. _ignoreSubscribers also stays true, so pushState / replaceState calls made by other code no longer notify the router.
The throw usually comes from outside the router: a browser extension or a third-party script that wraps history.pushState, or the browser refusing the update. That is how #6286 (URL doesn't update after the tab is idle, closed as caused by an extension) and #4239 (Illegal invocation from a script proxying history) were closed. Those triggers are external, but the router shouldn't stay broken for the whole session after one failed write.
Complete minimal reproducer
https://tanstack.com/router/latest (the docs site runs on TanStack Router). Run the snippet below in its DevTools console.
Steps to Reproduce the Bug
- Open https://tanstack.com/router/latest.
- In the console, make the next
pushStatethrow once, just as an extension's wrapper might, then put the router's ownpushStateback and click three docs links:
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
const go = async (href) => {
document.querySelector(`a[href="${href}"]`).click()
await wait(1500)
return location.pathname
}
const routerPushState = history.pushState // the wrapper installed by createBrowserHistory
let once = true
history.pushState = function (...args) {
if (once) {
once = false
throw new Error('simulated failure')
}
return routerPushState.apply(history, args)
}
console.log(await go('/router/latest/docs/overview'))
history.pushState = routerPushState // pushState works normally again
console.log(await go('/router/latest/docs/routing/routing-concepts'))
console.log(await go('/router/latest/docs/api/router'))
- The page now shows "Router API", but all three logs print
/router/latestand the address bar stays there. Every later navigation is affected too, althoughpushStatehas been working again since the second click.
Expected behavior
A single failed history write affects only that navigation. The next navigation writes its URL as usual.
Screenshots or Videos
No response
Platform
- Router Version: @tanstack/react-router 1.170.45, @tanstack/history 1.162.5; same code on
main(08a419c) - OS: Linux, macOS
- Browser: Chrome, Brave
- Browser Version: current
- Bundler: Vite+ (Vite)
- Bundler Version: Vite+ 1.3.0
Additional context
A possible fix: clear the queued action before the browser call and always reset _ignoreSubscribers. Passing an explicit receiver also covers the case where win.history.pushState is the native method again (e.g. a script restored it), since native methods check this ("Illegal invocation").
const flush = () => {
if (!next) return
const [href, state, isPush] = next
next = undefined
rollbackLocation = undefined
history._ignoreSubscribers = true
try {
;(isPush ? win.history.pushState : win.history.replaceState).call(win.history, state, '', href)
} finally {
history._ignoreSubscribers = false
}
}
We run this as a pnpm patch (plus an optional retry one second later). With it, the snippet above leaves only the first navigation's URL unwritten (or retried), and every later navigation updates the address bar. Happy to open a PR with a regression test in tests/createBrowserHistory.test.ts if this direction is fine.
- 主要言語
- 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 が 18 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
TanStack/router の issue をすべて見る
似ている issue
-
[Docs] CONTRIBUTING points the Backend Remake milestone at a branch that does not exist対応中かも @franpts2 が今日担当しました。 オープンdocs
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 3 日以内に返信
-
ready-for-agent
難易度 2/5 半日 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
cloudflare/nimbus#423 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
[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 日以内に返信