lazyRouteComponent reloads over a navigation when Firefox/Safari cancel a pending route chunk on page leave
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 54/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
Start by reading the lazyRouteComponent implementation and the router plugin’s automatic code splitting path that imports it; the issue does not name file paths or tests. Reproduce with a slowly served route chunk in Firefox or Safari, then trace how a cancelled import triggers the reload during navigation away. Done means the browser follows the requested full navigation, with a regression test covering the cancellation case.
索引モデルが issue の本文から書いたものです。
説明
Which project does this relate to?
Router
Describe the bug
When a code-split route's chunk is still loading and the person leaves the page (clicks a link to another document, types an address, reloads), Firefox and Safari cancel the pending dynamic import. They reject it with the same messages as a missing chunk: "error loading dynamically imported module" in Firefox, "Importing a module script failed" in Safari.
lazyRouteComponent takes that as a stale deploy. It sets the tanstack_router_reload:<message> key and calls window.location.reload(). That reload of the old address replaces the navigation the person just started, and they land back on the page they were leaving.
There's no option to turn this off. The reload is hardcoded, the router plugin's automatic code splitting imports lazyRouteComponent by name, and the branch runs in the lazy component's render, before any errorComponent or onError sees the error.
Related, but a different trigger: #8377 and #8331.
Your Example Website or App
Any app with automatic code splitting. A small repro follows.
Steps to Reproduce the Bug or Issue
- Build an app with automatic code splitting. Serve its chunks slowly, for example with a proxy that delays
.jsresponses by a few seconds. - Open the app in Firefox or Safari.
- Click a link to a route whose chunk hasn't loaded yet.
- While that chunk is still loading, start a full navigation away: type another URL (same origin or not) and press Enter, or follow a plain
<a href>to another document.
Expected behavior
The browser goes to the address the person asked for.
Actual behavior
The import is cancelled with a missing module's message, lazyRouteComponent calls window.location.reload(), and the page reloads at the old address instead of following the navigation. In end-to-end tests this shows up as Playwright's page.goto in Firefox ending on the previous URL.
Platform
- Router version: 1.170.46 (the code is the same in 1.170.45)
- Browsers: Firefox and Safari (WebKit). Chromium doesn't cancel the import with this message.
Additional context
We work around it with a local patch. A beforeunload listener sets a module-level leaving flag. While the flag is set, Lazy suspends instead of reloading, since the page is going away anyway:
let leaving = false
let staying = []
if (typeof window !== 'undefined') {
const stay = () => {
leaving = false
const waiting = staying
staying = []
for (const resolve of waiting) resolve()
}
window.addEventListener('beforeunload', () => { leaving = true })
// Some browsers fire beforeunload for mailto:/tel: links without leaving, so the
// first sign the page is still in use ends the suspension and the route reloads once as before.
window.addEventListener('pageshow', stay)
window.addEventListener('pointerdown', stay, true)
window.addEventListener('keydown', stay, true)
}
// in Lazy, before the sessionStorage guard:
if (leaving) throw new Promise((resolve) => staying.push(resolve))
We'd be glad to drop the patch for an upstream fix: either this behavior, or an option to opt out of the automatic reload or handle it ourselves.
- 主要言語
- 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 日以内に返信