-
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
warn when a propName looks like a mistyped event #3885
Conversation
var eventType = key.replace(/^top/, 'on'); | ||
eventTypesAccumulator[eventType.toLowerCase()] = eventType; | ||
return eventTypesAccumulator; | ||
}, {}); |
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.
I think we probably want this in a __DEV__
block so we aren't doing extra startup work in prod (it might get dead code eliminated but not certain)
We'll need to rebase and fix a couple things but overall it seems fine to me. Any thoughts @spicyj? |
fixes added @zpao |
if (__DEV__) { | ||
Object.keys(props).forEach(function(propName) { | ||
warning( | ||
!eventTypes.hasOwnProperty(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.
This would for example not catch onMouseup
. Maybe something like the following would be better?
var eventType = eventTypes[propName.toLowerCase()];
warning(
!eventType || eventType === 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.
good catch
how about building a regexp with the case insensitive flag when creating the map, and test anything matching the pattern, but not equal to the valid 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.
and would fail with this edge-case:
var eventTypes = {}
var eventType = eventTypes["constructor"]
!eventType || eventType === "constructor" // false
topLevelTypes is the wrong thing to look at here. It doesn't include custom React events like onMouseEnter and onMouseLeave. Instead, you want to look at the "registration names" gathered at the top of each event "plugin": react/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js Lines 37 to 43 in 8f96434
These are collected in EventPluginRegistry: Hopefully that gives you some clues to go on. I also don't love that the warning logic for DOM properties
is in a totally different place. We should at least make the error messages a little more similar. |
I think we're going to go with #5361. |
closes #3548