-
Notifications
You must be signed in to change notification settings - Fork 50.2k
Throw more specific error if passed undefined in React.cloneElement #12534
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
Changes from 1 commit
7bc5fd5
8ee2452
33d1edf
48c7b53
34816fc
2733707
44df599
7f6d18b
baa4d84
80de944
e3416ee
905abfc
d20de72
070ef20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,8 +293,8 @@ export function cloneAndReplaceKey(oldElement, newKey) { | |
| */ | ||
| export function cloneElement(element, config, children) { | ||
| invariant( | ||
| !(element === null || element === undefined), | ||
| 'Cannot clone a null or undefined element.' | ||
| !(element === null || element === undefined), | ||
| 'Cannot clone a null or undefined element.' | ||
|
||
| ); | ||
|
|
||
| let propName; | ||
|
|
||
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.
We could just use a loose equality check here
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.
Ah right yes, because the type conversion will catch undefined 👍
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.
FWIW, we've intentionally stopped using loose checks a while ago because they sometimes cause engine deoptimizations. I'd prefer strict ones.
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.
@gaearon didn't know that. We still have tons of places where we use loose equality checks.
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.
@gaearon okay gotcha, reverted that.
@aweary I can look into switching some over in a PR maybe? That should be pretty straightforward and I would love the opportunity to get more familiar with the codebase.
Uh oh!
There was an error while loading. Please reload this page.
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.
@nicolevy I don't know, I'm not sure it's worth it? It could be helpful to make the changes and then somehow benchmark them. I'd also be interested in seeing a profile that shows the current deoptimizations and their impact as well. Making all the checks strict would increase the overall bundle size, so there are other costs to consider.
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.
@aweary hmmm okay, I’ll wait until a decision is made before I start on that then.