Skip to content

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

Open

Description

@loganrosen

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.

Activity

  1. aron-intframe commented on Oct 23, 2026

    @aron-intframe

    Confirmed on 1.170.46, and 1.170.19 is already bad, so the bisect point in the report holds. I reproduced it without your reproducer repo: node 24 + jsdom, lazyRouteComponent for the ancestor errorComponent, child loader throws, no defaultErrorComponent, and an import() counter on the lazy chunk.

    1.170.18 / core 1.171.15
    after load(): ParentError chunk requested = true
    first commit: "Parent errorComponent"
    
    1.170.19 / core 1.171.16   and   1.170.46 / core 1.171.39
    after load(): ParentError chunk requested = false
    first commit: ""
    +500ms:       "Parent errorComponent"
    

    Cause: the not-found path walks up to the boundary that renders, the error path does not.

    • In reduceLane, boundaryOf returns getNotFoundBoundary(...) for NOT_FOUND but plain found[0] for ERROR, so the preload is loadRouteChunk(route, "errorComponent") on the errored match only.
    • The ancestor is success, so its chunk went through loadComponents(), i.e. component + pendingComponent. Core 1.171.15 defaulted to all four componentTypes, which pulled the ancestor's errorComponent in as a side effect.
    • Match installs no CatchBoundary for a match with neither its own errorComponent nor defaultErrorComponent, so the error lands on a boundary whose chunk nobody requested.

    Three neighbouring cases behave the same on 1.170.18 and 1.170.46, so the hole is only the ancestor error boundary:

    own-error          first commit="Child errorComponent"
    ancestor-notfound  first commit="Parent notFoundComponent"
    default-error      first commit="DEFAULT error"
    

    Giving ERROR the same upward walk fixes it. The lazy options have to resolve before options.errorComponent can be read, since that is where it arrives:

    for (let i = index; i >= 0; i--) {
      const route = getRoute(router, matches[i])
      const loading = loadRouteChunk(route, false)
      if (loading) await waitFor(loading, signal)
      if (route.options.errorComponent) return loadRouteChunk(route, 'errorComponent')
      if (i === index && router.options.defaultErrorComponent) return
    }

    Patched into the ERROR branch of reduceLane in installed 1.171.39: first commit: "Parent errorComponent", and the three cases above are unchanged.

    hydrate() selects a single component type the same way, so an SSR error page may have the same hole on hydration. I did not test that.

    Disclosure per CONTRIBUTING: diagnosed by an AI agent. Every command and every line of output above was actually run, not predicted.

    Blank-first-paint after a green load is a class we keep hitting; the check we run for it is in our repo (ours): https://github.com/aron-intframe/agent-guards/blob/main/guards/paint-check.js

  2. self-assigned this
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions