-
Notifications
You must be signed in to change notification settings - Fork 45.6k
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 about unknown property values #267
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 |
---|---|---|
|
@@ -28,6 +28,36 @@ var processAttributeNameAndPrefix = memoizeStringOnly(function(name) { | |
return escapeTextForBrowser(name) + '="'; | ||
}); | ||
|
||
if (__DEV__) { | ||
var reactProps = { | ||
'{owner}': true, | ||
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. We should maybe just export this from ReactComponent, but then requiring it might lead to some circular dependencies :/ 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. The proper fix for this is probably to move 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. Yes. This needs to get out of props at some point. Definitely. I think it's fine to do that separately. |
||
children: true, | ||
dangerouslySetInnerHTML: true, | ||
key: true, | ||
ref: true | ||
}; | ||
var warnedProperties = {}; | ||
|
||
var warnUnknownProperty = function(name) { | ||
if (reactProps[name] || warnedProperties[name]) { | ||
return; | ||
} | ||
|
||
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]; | ||
if (standardName != null) { | ||
message += ' Did you mean ' + standardName + '?'; | ||
} | ||
|
||
console.warn(message); | ||
}; | ||
} | ||
|
||
/** | ||
* Operations for dealing with DOM properties. | ||
*/ | ||
|
@@ -55,6 +85,9 @@ var DOMPropertyOperations = { | |
return processAttributeNameAndPrefix(name) + | ||
escapeTextForBrowser(value) + '"'; | ||
} else { | ||
if (__DEV__) { | ||
warnUnknownProperty(name); | ||
} | ||
return null; | ||
} | ||
}, | ||
|
@@ -85,6 +118,10 @@ var DOMPropertyOperations = { | |
} | ||
} else if (DOMProperty.isCustomAttribute(name)) { | ||
node.setAttribute(name, value); | ||
} else { | ||
if (__DEV__) { | ||
warnUnknownProperty(name); | ||
} | ||
} | ||
}, | ||
|
||
|
@@ -110,6 +147,8 @@ var DOMPropertyOperations = { | |
} | ||
} else if (DOMProperty.isCustomAttribute(name)) { | ||
node.removeAttribute(name); | ||
} else if (__DEV__) { | ||
warnUnknownProperty(name); | ||
} | ||
} | ||
|
||
|
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.
@petehunt might actually complain about this and opt for setting each individually to avoid allocating an object here (though it gets allocated in the constructor anyway so it's probably not the end of the world.
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.
Right, I figured that the constructor will allocate the same object so it doesn't make a difference.