-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Allow custom attributes by default #7311
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
afae07c
Allow custom attributes. Add flag to toggle custom attribute behavior
nhunzaker 3388f4f
Update custom attribute logic
nhunzaker 9f7a696
Allow numbers and booleans custom attributes. Cut isCustomAttribute
nhunzaker fd94756
Cover objects with custom attributes in warning test
nhunzaker f870980
Rename DOMProperty.isWriteable to shouldSetAttribute
nhunzaker ab64ef3
Rework conditions in shouldSetProperty to avoid edge cases
nhunzaker 7717ed7
Update unknown property warning to include custom attribute information
nhunzaker 2b402a4
Remove ref and key from reserved props
nhunzaker 1681e7f
Ensure SSR test coverage for DOMProperty injections
nhunzaker b5736c7
Add ajaxify attribute for internal FB support
nhunzaker 976ca82
Ajaxify is a stringifiable object attribute
nhunzaker 17d3c49
Update test name for custom attributes on custom elements
nhunzaker 40dee5a
Remove SSR custom injection test
nhunzaker b26384d
Remove onAfterResetModules hooks in SSR render tests
nhunzaker d672771
Do not allow assignment of attributes that are aliased
nhunzaker a871d55
Update custom attribute test to check value, not just presence
nhunzaker c748e84
Address case where class is assigned as an attribute on custom elemen…
nhunzaker 16dd18a
Cover cases where className and for are given to custom elements
nhunzaker e68bf4d
Remove unnecessary spys on console.error. Reduce extra space in tests
nhunzaker 83e46aa
Cover cased custom attributes in SSR tests
nhunzaker facfa87
Custom attributes are case sensitive
nhunzaker 82e05e0
Allow uppercase letters in custom attributes. Address associated edge…
nhunzaker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.