router icon indicating copy to clipboard operation
router copied to clipboard

`loader` promise never resolves when error thrown in params.parse from deep route

Open lislon opened this issue 4 months ago • 0 comments

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 in params.parse, catch it in onError and re-throw it as throw 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

  1. Open example app
  2. Click on "Click to go to /rotten"

Infinite pendingComponent will be shown 'Loading...'

Expected behavior

I expect to see notFoundComponent

Screenshots or Videos

Image

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: Version 129.0.6668.101 (Official Build) (64-bit)

Additional context

No response

lislon avatar Oct 12 '24 00:10 lislon