-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Fix #6153: Warn for PropTypes that don't exist but do exist with a di… #6255
Conversation
|
||
if (__DEV__) { | ||
var warnMiscapitalizedPropName = function(componentName, | ||
allPropNames, |
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.
The indentation here is not consistent with the rest of our code.
Overall, this looks good. Just a few nitpicks. Also, can you add a full-path test that actually creates a component with a proptype specified, and then calls |
@jimfb I implemented and ran the test you described and here's what happened: the warning was output twice. Once with |
That would imply that We are probably going to need to add some deduplication logic into your devtool anyway. We don't the warning to fire every single time the component is rerendered. You can take a look at the other places we emit warnings (eg. DOMPropertyOperations.js contains |
@ahmedghoneim92 updated the pull request. |
@jimfb I found the two places from which it gets called. Once from I've updated my code with a cache of miscapitalized propNames, is this okay, or should I cache the (componentName, propName) combination? |
Re-based code from facebook#6255
var missingPropNameLowerCase = missingPropName.toLowerCase(); | ||
var incorrectlyCapitalizedPropName; | ||
|
||
for (var propName of allPropNames) { |
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.
Please don’t use for of
syntax as it relies on ES6 Symbol
being available, and we don’t polyfill it.
As I wrote in #6255 (comment), In general, I’m not sure if firing events about propTypes being checked is something we want to do. Since we plan to eventually remove them from the core, we don’t want to couple them to Also, is this a breaking change? I can imagine some components in the ecosystem might have incorrect Overall I see how this might be useful but I’m not sure if checking casing is how I’d approach this. This is a subset of a more general problem: warning for extraneous prop types. We discussed this in #1587 but I don’t think it went anywhere because of the pattern of transferring props. I’m probably not the right person to review this. @spicyj and @sebmarkbage might have more context on this. So I’m just commenting to explain why we might not be ready to proceed with this. |
That's going to be an issue with every warning we add. Yet, we need to add warnings. Plausible solutions include blackboxing warnings or version flags on the warning modules so you can opt-in to only new warnings. Orthogonal to this PR, but might affect which version it gets merged into.
That is true but since that's a much more substantial change, we might as well move quickly on this one. Even with the other warning, checking for casing is a better error message than just "typo". You can give the user a concrete suggestion for the fix. I share the concern about exposing this contract in the devtool though. As a meta-point I'm skeptical of the architecture of building warnings in the devtool. I think it's over architected. I think it makes a lot more sense to just expose a "warning" hook in the devtool that lets it do what it wants with it, but not building the warnings themselves in the devtool. It exposes too many fast moving implementation details. |
As in, core emits the warnings, devtools decide whether to log / present / record them? |
If you have incorrect proptypes, the component is broken. What is the point of avoiding errors for something that is most likely broken than not? |
why this isn't merged? |
No description provided.