lazyRouteComponent reloads over a navigation when Firefox/Safari cancel a pending route chunk on page leave
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 54/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 15.3k
- Fork
- 1.9k
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 46
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/router
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')Có thể đã có người làm @hassanabrar202 đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)Có thể đã có người làm @Sheraff đã nhận 27 ngày trước. Đang mởpackage: router-generator performance
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiersCó thể đã có người làm @Sheraff đã nhận 27 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(router): clarify static title fallback in SPA modeCó thể đã có người làm @Rohan-Dedhia đã nhận 17 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/router
Issue tương tự
-
[BUG]: Shared links drop the configured basePath on GitHub PagesCó thể đã có người làm @anshulchikhale30-p đã nhận hôm nay. Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: GTrekkerĐang mởcheck:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ui Bug Payload OSS
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
payloadcms/payload#19839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
Maintainer thường phản hồi trong vòng 1 ngày