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

False type safety with meta v2 #6210

Closed
1 task done
AlemTuzlak opened this issue Apr 27, 2023 · 6 comments · Fixed by #6231
Closed
1 task done

False type safety with meta v2 #6210

AlemTuzlak opened this issue Apr 27, 2023 · 6 comments · Fixed by #6231

Comments

@AlemTuzlak
Copy link
Contributor

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

@machour
Copy link
Collaborator

machour commented May 4, 2023

This is the same as #5786 and it will be fixed by merging #5787
Closing as a duplicate to keep our issues tracker clean

@machour machour closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
@AlemTuzlak
Copy link
Contributor Author

@machour sorry for the duplicate! Didn't see that issue

@machour
Copy link
Collaborator

machour commented May 4, 2023

no worries, I didn't even see that it was already fixed 😅

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2023

🤖 Hello there,

We just published version v0.0.0-nightly-d8bcdc1-20230506 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 1.16.1-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 1.16.1 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging a pull request may close this issue.

3 participants