-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[core] Replace warning with manual console.error #17404
Conversation
37ca623
to
e276987
Compare
Details of bundle changes.Comparing: 6a65aa7...ceafa54
|
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.
- Sounds good
- You, me and many more from what I have heard so far :)
- Nice, should we do a follow-up effort to decide when using warning and error?
- I'm happy to see one less dependency in the package.json :)
I have mixed feelings about __DEV__
, I like how it's shorter to write, how it matches what React does but I dislike the extra transformation step, making people wonder how it will be transpiled. Overall, it might have more pros than cons.
@@ -110,7 +109,8 @@ function attach({ state, theme, stylesOptions, stylesCreator, name }, props) { | |||
...options, | |||
}); | |||
|
|||
warning(props, 'Material-UI: props missing.'); | |||
// never true | |||
// warning(props, 'Material-UI: props missing.'); |
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.
It seems that we could easily fix it by removing the default prop value (in return (props = {}) => {
).
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.
useStyles()
is fairly common looking at all the TS issues. Supporting this makes sense since most styles aren't dynamic. I would however question why we need the default value anyway. Rather we should let this flow through and either let it crash with the usual null-pointer exception and rely on a typed language or throw a custom TypeError.
); | ||
}); | ||
|
||
CardMedia.propTypes = { | ||
/** | ||
* |
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.
Should we add a description? It always feels weird to me when I have to add one for this prop.
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.
Oh sure.
Children should always be explicit. There are a lot of misconceptions about this prop which mostly stem from people assuming they "just work". This is bascially true for every component in this library but only because our components are very close to the DOM. The bigger the component the less obvious what kind of children are handled if any.
Me too, let's kill it. It would be simpler with rollup but since it's just a write-helper I'm not too attached to it. |
Co-Authored-By: Olivier Tassinari <olivier.tassinari@gmail.com>
Review on per-commit basis is advised.
Replace problematic
warning(condition, message)
withwarning
tripped me personally all the time and I suspect others as well: does this warn if the condition is true or false?1console.warn
orconsole.error
Point 3 is the main selling point here.
warning
usingconsole.error
and starting the message withWarning
was always confusing. We don't need to propagate this problematic choice by using even more fb code but rather use the platform specific methods (console.error and console.warn).This PR is part of a larger effort to improve DX which is split up to allow review.
1
It automatically removes double negations if you had
warning(!children, 'children should not be provided')
which becameif !!children then log a warning
in your head.Help with #15343