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

未关闭
#8,792 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@Sheraff 已经在做这个了。

开始于 2026年10月23日。

  • #8793 来自 @sarankumar1325 —— 已关闭,未合并
  • #8896 来自 @EnesKartal —— 未关闭

评估

难度
4/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
react, typescript, vite
领域
frontend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
15.3k
派生
1.9k
平均合并
1 天 5 小时
30 天内合并 PR
46

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/router 的其他 Issue

查看 TanStack/router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。