-
Notifications
You must be signed in to change notification settings - Fork 34
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
patch: improve error message #609
Conversation
…a react component inside the jsx
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArnavK-09 can u show if this works using yalc package??
BEFOREAFTER |
@@ -466,6 +466,11 @@ export abstract class PrimitiveComponent< | |||
} | |||
|
|||
add(component: PrimitiveComponent) { | |||
if (!component.onAddToParent) { | |||
throw new Error( | |||
"Invalid JSX Element: Expected a React component but received a non-component value. Ensure you are using a valid component (function or class) and that it's properly imported.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you attempt to stringify it to make the error message even better.
Also no need for the latter half
"Invalid JSX Element: Expected a React component but received a non-component value. Ensure you are using a valid component (function or class) and that it's properly imported.", | |
"Invalid JSX Element: Expected a React component but received "...". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, can we improve the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.stringify fails sometimes no? we don't want to accidentally throw an unrelated error (I think)
</board>, | ||
) | ||
}).toThrowError("Invalid JSX Element") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure to test with new ClassName()
because i think JSON.stringify could error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or you could put in a function or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh it's pretty hard to break JSON.stringify
/claim #556
Before
After