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
Boolean attributes no longer coerced to string #9779
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 |
---|---|---|
|
@@ -203,6 +203,13 @@ describe('DOMPropertyOperations', () => { | |
expect(stubNode.getAttribute('role')).toBe('<html>'); | ||
}); | ||
|
||
it('should set values as boolean attributes', () => { | ||
DOMPropertyOperations.setValueForProperty(stubNode, 'data-foo', true); | ||
expect(stubNode.getAttribute('data-foo')).toBe(''); | ||
DOMPropertyOperations.setValueForProperty(stubNode, 'data-foo', false); | ||
expect(stubNode.getAttribute('data-foo')).toBe(null); | ||
}); | ||
|
||
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. Is this true? No matter how I assign data attributes, they always appear, regardless of boolean values: 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. That is correct; |
||
it('should not remove empty attributes for special properties', () => { | ||
stubNode = document.createElement('input'); | ||
ReactDOMComponentTree.precacheNode(stubInstance, stubNode); | ||
|
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.
This change worries me. This would be breaking behavior since we currently just stringify
false
and this would potentially change runtime behavior. I think we should leave this specific part as-is, wherenull
is used to identify attributes that should be removed.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.
E.g.
spellcheck
is not a boolean attribute and expects the value'true'
or'false'
, if anyone relies on boolean being stringified today it will break for them (I assume? or is that another codepath). Also note that neither'true'
nor'false'
is the default value for it.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.
Are there any other enumerated attributes like that which use stringified booleans? I would hate to special case them, but I also think it's reasonable to ask users to provide the expected stringified values themselves, e.g.,
spellcheck="true"
. We could have dev-only warnings for that maybe.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.
Also, using "true" and "false" but not making it a boolean attribute seems like a really confusing decision 🤔
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.
#9806 seems relevant to this as well.
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 don't know if there is any cross over with #9806, but I'm curious, if we move forward with this, how
value
should be treated.We have a special mutation method for
value
that might need to be synced up with this new logic, but as far as I see it,value={true}
should stringify to"true"
, which is what would happen if you mutated the input directly.