router.load() resolves before an ancestor boundary's code-split errorComponent is loaded (regression in 1.170.19)

Đang mở
#8,792 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Sheraff đang làm issue này rồi.

Từ ngày 23/10/2026.

  • #8793 của @sarankumar1325 — đã đóng, không merge
  • #8896 của @EnesKartal — đang mở

Đá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
55/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, vite
Lĩnh vực
frontend

Hướng nghiên cứu

Start by tracing router.load() and route chunk loading, especially how an errored child selects an ancestor’s errorComponent; the report points to a regression introduced in 1.170.19 and possibly related to #7926. Use the linked reproducer and its failing test, then compare behavior with 1.170.18. Done means the boundary component is loaded when router.load() resolves and the regression test passes.

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

Since 1.170.19, router.load() can resolve before the chunk for the errorComponent that will actually render has loaded. As a result, the first render after load() suspends and is empty.

This happens when a child's loader throws, the child has no errorComponent, and an ancestor's errorComponent is code-split (which autoCodeSplitting does by default). The errored match only loads its own errorComponent, and the ancestor is success so it only loads component. So nothing preloads the boundary that catches the error. Before 1.170.19, every matched route's chunk loaded all of its component types, so this worked.

const parent = createRoute({
  getParentRoute: () => rootRoute,
  path: '/parent',
  errorComponent: lazyRouteComponent(() => import('./ParentError'), 'ParentError'),
  component: () => <Outlet />,
})

const child = createRoute({
  getParentRoute: () => parent,
  path: '/child',
  loader: () => {
    throw new Error('child loader failed')
  },
  component: () => <p>Child</p>,
})

await router.load()
flushSync(() => createRoot(el).render(<RouterProvider router={router} />))
// 1.170.18: el.textContent === 'Parent errorComponent'
// 1.170.46: el.textContent === '', the error component shows up once the chunk arrives

In the browser this is an empty frame. Under Testing Library (IS_REACT_ACT_ENVIRONMENT), the suspended render inside sync act() is never retried, so a test that awaits router.load() and then renders sees a blank page forever. That's how I found it.

Complete minimal reproducer

https://github.com/loganrosen/tanstack-router-load-lazy-error-component

Steps to Reproduce the Bug
  1. pnpm install && pnpm dev, then open the page. The log at the top shows what the first commit after router.load() contained.
  2. On 1.170.46 it logs first commit: "" and then +312.0ms: "Parent errorComponent".
  3. Set @tanstack/react-router to 1.170.18, pnpm install, reload. It logs first commit: "Parent errorComponent".
  4. pnpm test fails on 1.170.46 and passes on 1.170.18.
Expected behavior

When router.load() resolves, the errorComponent/notFoundComponent of the boundary that will render the error should already be loaded, like it was before 1.170.19. The API docs say load() "resolves when they are all loaded and ready to be rendered".

Screenshots or Videos

No response

Platform
  • Router / Start Version: @tanstack/react-router 1.170.46 (router-core 1.171.39); works on 1.170.18 (router-core 1.171.15)
  • OS: macOS
  • Browser: WebKit (macOS system webview)
  • Bundler: vite
  • Bundler Version: 8.3.5
Additional context

Found while upgrading the router in matrix-authentication-service (element-hq/matrix-authentication-service#6069). We're working around it in our test helper by calling router.loadRouteChunk(route, 'errorComponent') for every match after load(). Possibly related to the loader rewrite in #7926.

The issue was written with help from an AI coding assistant. I ran and checked the reproducer myself.

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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/router

Tất cả issue của TanStack/router

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.