Skip to content

False type safety with meta v2 #6210

@AlemTuzlak

Description

@AlemTuzlak

What version of Remix are you using?

v1.15

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

  • Create a new remix project with the basic config
  • Go into the routes/_index file
  • Create a loader like the following:
export const loader = () => {
  throw new Error();
  return json({
    title: "some title",
  });
};
  • Change the meta function to the following:
export const meta: V2_MetaFunction<typeof loader> = ({ data }) => {
  return [{ title: data.title }];
};
  • Add an error boundary (eg):
export const ErrorBoundary = () => {
  return (
    <div>
      <h1>Oops, something went wrong!</h1> 
    </div>
  );
};

Expected Behavior

When you do V2_MetaFunction<typeof loader> in the meta function the data object is typed as T | undefined where T corresponds to the typeof loader which warns the developer that the data object might not be defined and allows the developer to assure that the application doesn't break instead of it going into the error boundary.

Actual Behavior

When you do V2_MetaFunction<typeof loader> in the meta function the data object is typed as T where T corresponds to the return type of typeof loader which gives you a false sense of security because if anything unexpected in the loader breaks the data object won't be available on the meta function so if you try calling data.title instead of data?.title it won't go into the error boundary but it will crash the application instead

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