mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Log unknown props only when we have a match
Logging every unknown property got very noisy when combined with use of `transferPropsTo`. I knew this would be a potential issue initially but decided it was worth it. Others disagreed and it's resulting in some confusion. This changes the logging to ensure that we have a potential correction, so only DOMish properties should result in warnings.
This commit is contained in:
committed by
Paul O’Shannessy
parent
647731e399
commit
4ed7b85ed8
@@ -44,17 +44,20 @@ if (__DEV__) {
|
||||
}
|
||||
|
||||
warnedProperties[name] = true;
|
||||
var message = 'Unknown DOM property ' + name + '.';
|
||||
var lowerCasedName = name.toLowerCase();
|
||||
|
||||
// data-* attributes should be lowercase; suggest the lowercase version
|
||||
var standardName = DOMProperty.isCustomAttribute(lowerCasedName) ?
|
||||
lowerCasedName : DOMProperty.getPossibleStandardName[lowerCasedName];
|
||||
|
||||
// For now, only warn when we have a suggested correction. This prevents
|
||||
// logging too much when using transferPropsTo.
|
||||
if (standardName != null) {
|
||||
message += ' Did you mean ' + standardName + '?';
|
||||
console.warn(
|
||||
'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?'
|
||||
);
|
||||
}
|
||||
|
||||
console.warn(message);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -151,24 +151,18 @@ describe('DOMPropertyOperations', function() {
|
||||
|
||||
describe('injectDOMPropertyConfig', function() {
|
||||
it('should support custom attributes', function() {
|
||||
spyOn(console, 'warn');
|
||||
|
||||
// foobar does not exist yet
|
||||
expect(DOMPropertyOperations.createMarkupForProperty(
|
||||
'foobar',
|
||||
'simple'
|
||||
)).toBe(null);
|
||||
|
||||
expect(console.warn.argsForCall.length).toBe(1);
|
||||
|
||||
// foo-* does not exist yet
|
||||
expect(DOMPropertyOperations.createMarkupForProperty(
|
||||
'foo-xyz',
|
||||
'simple'
|
||||
)).toBe(null);
|
||||
|
||||
expect(console.warn.argsForCall.length).toBe(2);
|
||||
|
||||
// inject foobar DOM property
|
||||
DOMProperty.injection.injectDOMPropertyConfig({
|
||||
isCustomAttribute: function(name) {
|
||||
|
||||
Reference in New Issue
Block a user