Skip to content

Throwing notFound in beforeLoad does not resolve pending state #6021

@mluiten

Description

@mluiten

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 #2514 which hasn't been touched for a year

Metadata

Metadata

Assignees

No one assigned

    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