Description
What version of React Router are you using?
6.24.1
Steps to Reproduce
Guide on createBrowserRoute docs using Co-locating route discovery with route definition
unstable_patchRoutesOnMiss: async ({ matches, path, patch }) => {
const leafRoute = matches[matches.length - 1]?.route
const maybeLazyChildren = leafRoute?.handle?.lazyChildren
if (maybeLazyChildren) {
const dynamicRoutes = await maybeLazyChildren()
return patch(leafRoute.id, dynamicRoutes)
}
}
Expected Behavior
When maybeLazyChildren
throws an error eg. due to network error within unstable_patchRoutesOnMiss
, it should allow the error to be captured by one of the error-boundaries defined for the router. This would allows users to customize the error-handling behaviour similarly as with current lazy based approach.
Actual Behavior
Throwing an error within unstable_patchRoutesOnMiss
results in the same behaviour as returning undefined
from the function.
One option I was experimenting with was to handle the error in the userland within the unstable_patchRoutesOnMiss
and return a element
showing an error-screen instead, but this wouldn't allow users to retry & recover since the discovery happens just once.