Skip to content

throwing object from streaming loader does not work on client navigation  #12676

@cloudkite

Description

@cloudkite

I'm using React Router as a...

framework

Reproduction

behaviour observed with both <Await> and use()

using use hook:
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-gdwvvw2y?file=app%2Froutes%2Fitem-stream.tsx

using Await component:
https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-sn1xvkxt?file=app%2Froutes%2Fitem-stream.tsx

Expected Behavior

When defining a loader that returns a promise that can reject with a custom object:

export function loader({ params }: Route.LoaderArgs) {
  let getItem = async () => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    if (params.itemId !== '1') {
      throw { code: 'NOT_FOUND' };
    }
    return { name: 'hello' };
  };
  return { item: getItem() };
}

I would expect the ErrorBoundary to receive the custom object { code: 'NOT_FOUND' };

Actual Behavior

in the stackblitz example click item stream invalid link

opening a page using client navigation (via a link) that throws from a streamed promise the ErrorBoundary does not receive the custom object but instead receives Error: An unknown error occurred
CleanShot 2025-01-06 at 09 11 08@2x

however opening the same page with full refresh/ server render, produces the expected result:

CleanShot 2025-01-06 at 09 10 53@2x

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions