mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Fire unknown prop warning when rendering client side. (#6693)
This commit is contained in:
1 parent
503cbd3356
commit
2e881aa4b4
2 files changed
+39
-25
No files matched your search
@@ -1275,14 +1275,14 @@ describe('ReactDOMComponent', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn about incorrect casing on properties', function() {
|
||||
it('should warn about incorrect casing on properties (ssr)', function() {
|
||||
spyOn(console, 'error');
|
||||
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', tabindex: '1'}));
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toContain('tabIndex');
|
||||
});
|
||||
|
||||
it('should warn about incorrect casing on event handlers', function() {
|
||||
it('should warn about incorrect casing on event handlers (ssr)', function() {
|
||||
spyOn(console, 'error');
|
||||
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', onclick: '1'}));
|
||||
ReactDOMServer.renderToString(React.createElement('input', {type: 'text', onKeydown: '1'}));
|
||||
@@ -1291,6 +1291,22 @@ describe('ReactDOMComponent', function() {
|
||||
expect(console.error.argsForCall[1][0]).toContain('onKeyDown');
|
||||
});
|
||||
|
||||
it('should warn about incorrect casing on properties', function() {
|
||||
spyOn(console, 'error');
|
||||
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', tabindex: '1'}));
|
||||
expect(console.error.argsForCall.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toContain('tabIndex');
|
||||
});
|
||||
|
||||
it('should warn about incorrect casing on event handlers', function() {
|
||||
spyOn(console, 'error');
|
||||
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', onclick: '1'}));
|
||||
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', onKeydown: '1'}));
|
||||
expect(console.error.argsForCall.length).toBe(2);
|
||||
expect(console.error.argsForCall[0][0]).toContain('onClick');
|
||||
expect(console.error.argsForCall[1][0]).toContain('onKeyDown');
|
||||
});
|
||||
|
||||
it('should warn about class', function() {
|
||||
spyOn(console, 'error');
|
||||
ReactDOMServer.renderToString(React.createElement('div', {class: 'muffins'}));
|
||||
|
||||
@@ -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,7 +25,7 @@ if (__DEV__) {
|
||||
};
|
||||
var warnedProperties = {};
|
||||
|
||||
var warnUnknownProperty = function(name) {
|
||||
var warnUnknownProperty = function(name, source) {
|
||||
if (DOMProperty.properties.hasOwnProperty(name) || DOMProperty.isCustomAttribute(name)) {
|
||||
return;
|
||||
}
|
||||
@@ -35,7 +33,9 @@ if (__DEV__) {
|
||||
warnedProperties.hasOwnProperty(name) && warnedProperties[name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) {
|
||||
return;
|
||||
}
|
||||
warnedProperties[name] = true;
|
||||
var lowerCasedName = name.toLowerCase();
|
||||
|
||||
@@ -48,10 +48,6 @@ 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(
|
||||
@@ -59,7 +55,7 @@ if (__DEV__) {
|
||||
'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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user