Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated types for Meta function should handle error thrown in loader #12843

Open
lasseklovstad opened this issue Jan 23, 2025 · 0 comments
Open
Labels

Comments

@lasseklovstad
Copy link

I'm using React Router as a...

library

Reproduction

  1. throw an error in a Route loader
  2. The generated types asume the loaderData is always defined
  3. In my case when an error is thrown the data returned in the meta function is undefined
export const meta = ({ data: { id} }: Route.MetaArgs) => {
  return [
    {
      title: id
 },
  ];
};

export async function loader({ params: { id } }: Route.LoaderArgs) {
  if (!id ) {
    throw new Response("Not Found", { status: 404 });
  }
  return { id };
}

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
    Memory: 9.18 GB / 31.78 GB
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE       
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (128.0.2739.113)
    Internet Explorer: 11.0.19041.4355

Used Package Manager

npm

Expected Behavior

MetaArgs should take into account that the loader can throw an Error and the data from the loader can be undefined.

Actual Behavior

The types for data in the meta function is always defined (which is not true).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant