Skip to content

Commit 6451c86

Browse files
jimfbjim
authored andcommitted
Add warning for unknown properties.
1 parent 8ea1cf4 commit 6451c86

File tree

3 files changed

+65
-18
lines changed

3 files changed

+65
-18
lines changed

src/addons/transitions/ReactTransitionGroup.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,21 @@ var ReactTransitionGroup = React.createClass({
222222
));
223223
}
224224
}
225+
226+
// Do not forward ReactTransitionGroup props
227+
var props = Object.assign({}, this.props);
228+
delete props.transitionLeave;
229+
delete props.transitionName;
230+
delete props.transitionAppear;
231+
delete props.transitionEnter;
232+
delete props.childFactory;
233+
delete props.transitionLeaveTimeout;
234+
delete props.transitionEnterTimeout;
235+
delete props.component;
236+
225237
return React.createElement(
226238
this.props.component,
227-
this.props,
239+
typeof this.props.component === 'string' ? props : this.props,
228240
childrenToRender
229241
);
230242
},

src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ describe('ReactDOMComponent', function() {
148148
expect(console.error.argsForCall.length).toBe(2);
149149
});
150150

151+
it('should warn for unknown prop', function() {
152+
spyOn(console, 'error');
153+
var container = document.createElement('div');
154+
ReactDOM.render(<div foo="bar" />, container);
155+
expect(console.error.argsForCall.length).toBe(1);
156+
expect(console.error.argsForCall[0][0]).toContain(
157+
'Warning: Unknown prop foo. See https://fb.me/react-unknown-prop'
158+
);
159+
expect(console.error.argsForCall[0][0]).toContain(
160+
'ReactDOMComponent-test.js'
161+
);
162+
});
163+
151164
it('should warn about styles with numeric string values for non-unitless properties', function() {
152165
spyOn(console, 'error');
153166

src/renderers/dom/shared/devtools/ReactDOMUnknownPropertyDevtool.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ if (__DEV__) {
2222
dangerouslySetInnerHTML: true,
2323
key: true,
2424
ref: true,
25+
26+
defaultValue: true,
27+
valueLink: true,
28+
defaultChecked: true,
29+
checkedLink: true,
30+
innerHTML: true,
31+
suppressContentEditableWarning: true,
32+
onFocusIn: true,
33+
onFocusOut: true,
2534
};
2635
var warnedProperties = {};
2736

@@ -48,16 +57,6 @@ if (__DEV__) {
4857
null
4958
);
5059

51-
// For now, only warn when we have a suggested correction. This prevents
52-
// logging too much when using transferPropsTo.
53-
warning(
54-
standardName == null,
55-
'Unknown DOM property %s. Did you mean %s? %s',
56-
name,
57-
standardName,
58-
formatSource(source)
59-
);
60-
6160
var registrationName = (
6261
EventPluginRegistry.possibleRegistrationNames.hasOwnProperty(
6362
lowerCasedName
@@ -66,13 +65,33 @@ if (__DEV__) {
6665
null
6766
);
6867

69-
warning(
70-
registrationName == null,
71-
'Unknown event handler property %s. Did you mean `%s`? %s',
72-
name,
73-
registrationName,
74-
formatSource(source)
75-
);
68+
if (standardName != null) {
69+
warning(
70+
standardName == null,
71+
'Unknown DOM property %s. Did you mean %s? %s',
72+
name,
73+
standardName,
74+
formatSource(source)
75+
);
76+
} else if (registrationName != null) {
77+
warning(
78+
registrationName == null,
79+
'Unknown event handler property %s. Did you mean `%s`? %s',
80+
name,
81+
registrationName,
82+
formatSource(source)
83+
);
84+
} else {
85+
// We were unable to guess which prop the user intended.
86+
// It is likely that the user was just blindly spreading/forwarding props
87+
// Components should be careful to only render valid props/attributes.
88+
warning(
89+
false,
90+
'Unknown prop %s. See https://fb.me/react-unknown-prop %s',
91+
name,
92+
formatSource(source)
93+
);
94+
}
7695
};
7796

7897
var formatSource = function(source) {
@@ -85,6 +104,9 @@ function handleElement(element) {
85104
if (element == null || typeof element.type !== 'string') {
86105
return;
87106
}
107+
if (element.type.indexOf('-') >= 0 || element.props.is != null) {
108+
return;
109+
}
88110
for (var key in element.props) {
89111
warnUnknownProperty(key, element._source);
90112
}

0 commit comments

Comments
 (0)