`notFoundComponent` doesn't render when `notFound` is thrown in the loader since 1.28.2
Describe the bug
A route wrapped in Suspense either by setting the prop wrapInSuspense to true or defining a pendingComponent doesn't render the notFoundComponent or the defaultNotFoundComopnent when the notFound function is thrown in the loader.
Your Example Website or App
https://codesandbox.io/p/devbox/beautiful-archimedes-7vwmwj
Steps to Reproduce the Bug or Issue
To reproduce :
- Go to index route
Loadingis rendered instead ofNot found
Things that doesn't trigger the bug :
- There is no Promise in the loader or the Promise is faster
- The prop
wrapInSuspenseis set tofalse - The prop
pendingComponentis not set
Expected behavior
The prop notFoundComponent should be rendered when the notFound function is thrown in the loader even if the route is wrapped in Suspense and the Promise is taking longer to resolve.
Screenshots or Videos
No response
Platform
- OS: Windows
- Browser: Chrome
- Version: 124
Additional context
No response
router.hasNotFoundMatch() also always returns false, I think this is related.
Also ran into this today. This seems to be an intermittent issue; roughly 10% of the time, the notFound component is shown correctly. Maybe there's a race somewhere?
Maybe useful: When the bug appears, the router devtools show that the route's loaderPromise is pending.
Personally, I encounter the issue 100% of the time.
I also noticed that the route's loaderPromise stay stuck to pending when the bug happen.
Seems I encountered similar behaviour in
- #1795
The same undesired behaviour seems to occur from the beforeLoad function aswell. docs seem to suggest it's possible to throw this here although I could be wrong...
Yes I think it's a bug. The docs explicitly state:
You, the developer must throw a not-found error when a resource cannot be found. This can be done in beforeLoad, loader, or components using the
notFoundutility.
https://tanstack.com/router/latest/docs/framework/react/guide/not-found-errors