router icon indicating copy to clipboard operation
router copied to clipboard

Throwing notFound in beforeLoad does not resolve pending state

Open mluiten opened this issue 3 weeks ago • 0 comments

Which project does this relate to?

Router

Describe the bug

When throwing a notFound() in the beforeLoad of a child route, the pendingComponent of a parent route keeps on the foreground. The status of the router remains in "pending".

I think this is probably because the pending components also depend on Suspense which throw promises instead of errors? But that's just a hunch. See the stackblitz for a simple example.

Funny enough I had a more difficult time replicating this issue with the code-based example, but that could be my incompetence.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-8atqgwzy?file=src%2Froutes%2Fposts.index.tsx

Steps to Reproduce the Bug or Issue

  1. Open stackblitz
  2. Go to the "Posts" tab -- a message "I am loading" should appear
  3. Wait 2 seconds
  4. notFound is thrown (see console)
  5. pendingComponent remains while notFound is...nowhere.

I've also tried it with the pathless in the same repo, but there it does seem to work somtimes, even though (or maybe because) it doesn't find the parent's notFoundComponent (is that another bug? or expected?)

Expected behavior

As a user I expect to see the "notFound" component when it's thrown, but I am seeing the "pendingComponent" forever

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.139.14
  • OS: macOS
  • Browser: any
  • Browser Version: any
  • Bundler: vite
  • Bundler Version: ^7.17

Additional context

Seems related to https://github.com/TanStack/router/issues/2514 which hasn't been touched for a year

mluiten avatar Dec 04 '25 16:12 mluiten