-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Allow custom attributes by default #7311
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
afae07c
3388f4f
9f7a696
fd94756
f870980
ab64ef3
7717ed7
2b402a4
1681e7f
b5736c7
976ca82
17d3c49
40dee5a
b26384d
d672771
a871d55
c748e84
16dd18a
e68bf4d
83e46aa
facfa87
82e05e0
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 |
---|---|---|
|
@@ -231,10 +231,7 @@ function setInitialDOMProperties( | |
} | ||
} else if (isCustomComponentTag) { | ||
DOMPropertyOperations.setValueForAttribute(domElement, propKey, nextProp); | ||
} else if ( | ||
DOMProperty.properties[propKey] || | ||
DOMProperty.isCustomAttribute(propKey) | ||
) { | ||
} else if (DOMProperty.shouldSetAttribute(propKey, nextProp)) { | ||
// If we're updating to null or undefined, we should remove the property | ||
// from the DOM node instead of inadvertently setting to a string. This | ||
// brings us in line with the same behavior we have on initial render. | ||
|
@@ -275,10 +272,7 @@ function updateDOMProperties( | |
} else { | ||
DOMPropertyOperations.deleteValueForAttribute(domElement, propKey); | ||
} | ||
} else if ( | ||
DOMProperty.properties[propKey] || | ||
DOMProperty.isCustomAttribute(propKey) | ||
) { | ||
} else if (DOMProperty.shouldSetAttribute(propKey, propValue)) { | ||
// If we're updating to null or undefined, we should remove the property | ||
// from the DOM node instead of inadvertently setting to a string. This | ||
// brings us in line with the same behavior we have on initial render. | ||
|
@@ -928,8 +922,7 @@ var ReactDOMFiberComponent = { | |
var extraAttributeNames: Set<string> = new Set(); | ||
var attributes = domElement.attributes; | ||
for (var i = 0; i < attributes.length; i++) { | ||
// TODO: Do we need to lower case this to get case insensitive matches? | ||
var name = attributes[i].name; | ||
var name = attributes[i].name.toLowerCase(); | ||
switch (name) { | ||
// Built-in attributes are whitelisted | ||
// TODO: Once these are gone from the server renderer, we don't need | ||
|
@@ -1019,28 +1012,37 @@ var ReactDOMFiberComponent = { | |
if (expectedStyle !== serverValue) { | ||
warnForPropDifference(propKey, serverValue, expectedStyle); | ||
} | ||
} else if ( | ||
isCustomComponentTag || | ||
DOMProperty.isCustomAttribute(propKey) | ||
) { | ||
} else if (isCustomComponentTag) { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propKey); | ||
extraAttributeNames.delete(propKey.toLowerCase()); | ||
serverValue = DOMPropertyOperations.getValueForAttribute( | ||
domElement, | ||
propKey, | ||
nextProp, | ||
); | ||
|
||
if (nextProp !== serverValue) { | ||
warnForPropDifference(propKey, serverValue, nextProp); | ||
} | ||
} else if ((propertyInfo = DOMProperty.properties[propKey])) { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propertyInfo.attributeName); | ||
serverValue = DOMPropertyOperations.getValueForProperty( | ||
domElement, | ||
propKey, | ||
nextProp, | ||
); | ||
} else if (DOMProperty.shouldSetAttribute(propKey, nextProp)) { | ||
if ((propertyInfo = DOMProperty.properties[propKey])) { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propertyInfo.attributeName); | ||
serverValue = DOMPropertyOperations.getValueForProperty( | ||
domElement, | ||
propKey, | ||
nextProp, | ||
); | ||
} else { | ||
// $FlowFixMe - Should be inferred as not undefined. | ||
extraAttributeNames.delete(propKey.toLowerCase()); | ||
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. Line 1031 properly removes attributes from the extraAttributeNames list because React assigns a lower cased version of the property name as |
||
serverValue = DOMPropertyOperations.getValueForAttribute( | ||
domElement, | ||
propKey, | ||
nextProp, | ||
); | ||
} | ||
|
||
if (nextProp !== serverValue) { | ||
warnForPropDifference(propKey, serverValue, nextProp); | ||
} | ||
|
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.
Is it not obvious to me why this is necessary. Do we have a test verifying this change? Can you add a comment as to why we do this?
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.
And is this only necessary for custom tags? What about custom attributes? If I do
<div myAttribute="" />
or<div data-MyAttribute="">
, does this also mess up server validation?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.
Interestingly, it looks there's a related todo a earlier in the document:
https://github.com/facebook/react/blob/master/src/renderers/dom/fiber/ReactDOMFiberComponent.js#L931
Accessing the attribute name from the DOM is always going to return a lower cased name, so we need to do this for regular DOM elements too. For consistency, and until we close the thread on this, I've added an adjustment and test in 83e46aa.
I think we really just need to decide if we care about allowing custom attributes to have custom casing. If not, we should add that logic to
shouldSetAttribute
and probably make a separate warning along the lines of "Custom attributes must be lowercase".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.
I'd be in favor if just warning when custom attributes use casing.