-
Notifications
You must be signed in to change notification settings - Fork 51k
Fire unknown prop warning when rendering client side. #6693
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,12 +13,10 @@ | |
|
|
||
| var DOMProperty = require('DOMProperty'); | ||
| var EventPluginRegistry = require('EventPluginRegistry'); | ||
| var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool'); | ||
|
|
||
| var warning = require('warning'); | ||
|
|
||
| if (__DEV__) { | ||
| var lastDebugID; | ||
| var reactProps = { | ||
| children: true, | ||
| dangerouslySetInnerHTML: true, | ||
|
|
@@ -27,15 +25,17 @@ if (__DEV__) { | |
| }; | ||
| var warnedProperties = {}; | ||
|
|
||
| var warnUnknownProperty = function(name) { | ||
| var warnUnknownProperty = function(name, source) { | ||
| if (DOMProperty.properties.hasOwnProperty(name) || DOMProperty.isCustomAttribute(name)) { | ||
| return; | ||
| } | ||
| if (reactProps.hasOwnProperty(name) && reactProps[name] || | ||
| warnedProperties.hasOwnProperty(name) && warnedProperties[name]) { | ||
| return; | ||
| } | ||
|
|
||
| if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) { | ||
| return; | ||
| } | ||
| warnedProperties[name] = true; | ||
| var lowerCasedName = name.toLowerCase(); | ||
|
|
||
|
|
@@ -48,18 +48,14 @@ if (__DEV__) { | |
| null | ||
| ); | ||
|
|
||
| var source = ReactComponentTreeDevtool.getSource(lastDebugID); | ||
| var formattedSource = source ? | ||
| `(${source.fileName.replace(/^.*[\\\/]/, '')}:${source.lineNumber})` : ''; | ||
|
|
||
| // For now, only warn when we have a suggested correction. This prevents | ||
| // logging too much when using transferPropsTo. | ||
| warning( | ||
| standardName == null, | ||
| 'Unknown DOM property %s. Did you mean %s? %s', | ||
| name, | ||
| standardName, | ||
| formattedSource | ||
| formatSource(source) | ||
| ); | ||
|
|
||
| var registrationName = ( | ||
|
|
@@ -75,29 +71,31 @@ if (__DEV__) { | |
| 'Unknown event handler property %s. Did you mean `%s`? %s', | ||
| name, | ||
| registrationName, | ||
| formattedSource | ||
| formatSource(source) | ||
| ); | ||
| }; | ||
|
|
||
| var formatSource = function(source) { | ||
| return source ? `(${source.fileName.replace(/^.*[\\\/]/, '')}:${source.lineNumber})` : ''; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| function handleElement(element) { | ||
| if (element == null || typeof element.type !== 'string') { | ||
| return; | ||
| } | ||
| for (var key in element.props) { | ||
| warnUnknownProperty(key, element._source); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, did this change make it so it does warn on non-SSR?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this devtool I mean.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this fixed the issue because the prop names were being filtered prior to this event firing, which means we only fire this event on props that are "correct". This is a reasonable behavior, because some devtools (eg. perf) might want to know about the DOM operations that are actually being performed, rather than every prop that was specified. We can re-think how/when those events fire, but that's a much longer discussion. |
||
| } | ||
| } | ||
|
|
||
| var ReactDOMUnknownPropertyDevtool = { | ||
| onCreateMarkupForProperty(name, value) { | ||
| warnUnknownProperty(name); | ||
| }, | ||
| onSetValueForProperty(node, name, value) { | ||
| warnUnknownProperty(name); | ||
| }, | ||
| onDeleteValueForProperty(node, name) { | ||
| warnUnknownProperty(name); | ||
| }, | ||
| onBeforeMountComponent(debugID, element) { | ||
| // TODO: This currently assumes that properties are all set before recursing | ||
| // and mounting children, which needn't be the case in the future. | ||
| lastDebugID = debugID; | ||
| handleElement(element); | ||
| }, | ||
| onBeforeUpdateComponent(debugID, element) { | ||
| lastDebugID = debugID; | ||
| handleElement(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.
Why was this necessary?
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.
Because previously we were processing only non-event properties because we were listening in setValueForProperty or whatever, but now we are just reading off the element so we need to filter out the events ourselves.