router
router copied to clipboard
`loader` promise never resolves when error thrown in params.parse from deep route
Which project does this relate to?
Router
Describe the bug
When the error is inside params.parse
, it doesn't reset parent's routes loader states and the UI is stuck in the loading state.
Configuration:
-
__root.tsx
with async loader +pendingComponent
+notFoundComponent
+wrapInSuspense: true
-
_reustarant.tsx
just a template for inner routes, no logic -
_reustarant/$pizzaType.tsx
here I throw an error inparams.parse
, catch it inonError
and re-throw it asthrow notFound()
// ..._root.tsx`
export const Route = createRootRoute({
component: RootComponent,
notFoundComponent: () => (
<div>
No pizza (this is expected)
</div>
),
pendingComponent: () => (
<div>
Loading...
</div>
),
loader: async () => {
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
await sleep(3000);
return { ok: true };
},
wrapInSuspense: true,
});
// ..._reustarant/$pizzaType.tsx`
export const Route = createFileRoute('/_reustarant/$pizza')({
component: Component,
params: {
parse: (p) => {
if (p.pizza === 'rotten') {
throw new Error('404 No rotten pizzas')
}
return {
pizza: p.pizza,
}
},
stringify: (p) => ({ pizza: p.pizza }),
},
onError: () => {
throw notFound()
},
})
Your Example Website or App
https://stackblitz.com/edit/github-efx5cv-t3bmly?file=README.md
Steps to Reproduce the Bug or Issue
- Open example app
- Click on "Click to go to /rotten"
Infinite pendingComponent
will be shown 'Loading...'
Expected behavior
I expect to see notFoundComponent
Screenshots or Videos
Platform
- OS: Windows
- Browser: Chrome
- Version: Version 129.0.6668.101 (Official Build) (64-bit)
Additional context
No response