Skip to content
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

Fix boolean element attributes as per HTML5 spec #993

Closed
wants to merge 11 commits into from

Conversation

jjt
Copy link

@jjt jjt commented Jan 29, 2014

No description provided.

@jjt
Copy link
Author

jjt commented Jan 29, 2014

Fixes #961

@@ -94,6 +94,9 @@ var DOMPropertyOperations = {
if (shouldIgnoreValue(name, value)) {
return '';
}
if (value === true && DOMProperty.hasBooleanValue[name]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that just be:

if (value && DOMProperty.hasBooleanValue[name]) {

If it's a boolean, then it's a boolean.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has to be if a value is strictly true, and not just truey. Otherwise a value of "myAttrValue" would emit a bare attribute. I guess that might be favourable to force HTML5 compliance. But it takes away the ability to target XHTML with disabled="disabled" (if that matters).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjt The issue I see with only strictly true values is that most things people use as booleans are often not strictly true or false, I mean even Var1 || Var2 could be anything.

As for XHTML, I'm not sure if React is even compatible with it anyway (and who even uses it, hehe), if that is something we strive to support (do we?) then I would argue that it's better to detect it and always mirror the key in the value, rather than this weird in-between.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? People play it fast and loose with js types?!!?

I tend to agree with you though inre: no XHTML support. It would fit with the current system of passing a falsey value to omit an attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say screw XHTML support and go bare. We've already decided we aren't ignoring the value (shouldIgnoreValue), so I think we should do it for all hasBooleanValue properties.

@syranide
Copy link
Contributor

@jjt Have you double-checked that all attributes marked as HAS_BOOLEAN_VALUE actually are and support bare attributes?

@jjt
Copy link
Author

jjt commented Jan 30, 2014

@syranide Yup, I went through the attributes and cross-referenced them with the ones in the spec.

@@ -94,6 +94,9 @@ var DOMPropertyOperations = {
if (shouldIgnoreValue(name, value)) {
return '';
}
if (value === true && DOMProperty.hasBooleanValue[name]) {
return escapeTextForBrowser(name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using attributeName just in case they don't match up.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, good call.

petehunt and others added 10 commits January 31, 2014 13:37
key should never be index into an array or there are bugs. Especially in
transitions.

Fixes facebook#853
We've been able to use `querySelectorAll` in all the browsers that we
support for some time now, but we haven't been able to test code that uses
it in the older version of `jsdom` that we were using, until recently.

Besides the general goal of modernizing our code, the impetus for this
specific change is that I'm trying to support testing without having to
render nodes into an actual document. The `.getElementsByName` method is
only defined on `document` and only works if the nodes you care about are
contained by the document.

On the other hand, `querySelectorAll` works on any DOM node, and allows a
more precise selection of just the `<input type="radio">` elements that
have the appropriate name.

IE8's implementation of `querySelectorAll` supports attribute-based
selectors, which is all we need here.
Numeric keys will be ordered sequentially in Chrome/Firefox.

Warn the user if such keys are set on a child.
We're not handling these correctly.
Number('.1') === 0.1, and react uses dot-prefixed keys
for children. Whoops. Nuke the non-numeric requirement, and just
check a regex. This seems performant enough in micro-benchmarks:
http://jsperf.com/numericlike
Recently learned that components passed into `React.renderComponent` may not be the ones actually mounted. Also learned that it returns the mounted component. Added some documentation describing this.
Let's be consistent with the naming
@jjt
Copy link
Author

jjt commented Jan 31, 2014

Alright, it's using attributeName and truthy testing now.

@syranide
Copy link
Contributor

@jjt Saw that you proposed using querySelectorAll instead of getElementsByName, I would guess that querySelectorAll is significantly slower than getElementsByName though.

@zpao
Copy link
Member

zpao commented Jan 31, 2014

@syranide I think that's from a rebase or something, we checked that in already. Though something funky is going on.

@jjt can you rebase so we only see your changes here?

@jjt
Copy link
Author

jjt commented Jan 31, 2014

@zpao Yeah, I don't know what happened with the commits. Will fix.

@syranide That was from mangled rebasing - I only pushed two commits, the rest are from me pulling in changes from master.

@jjt
Copy link
Author

jjt commented Jan 31, 2014

Nuking this one, see #1005

@jjt jjt closed this Jan 31, 2014
@syranide
Copy link
Contributor

@jjt FYI, if you run into this again, git reset --hard can be used to reset the branch.

@jjt
Copy link
Author

jjt commented Feb 1, 2014

@syranide Thanks, I'll look into that. I know just enough about git workflows to get myself into trouble, so it would be good to know how to dig myself out.

@syranide
Copy link
Contributor

syranide commented Feb 1, 2014

@jjt #459, we've all been there! :)

@jjt
Copy link
Author

jjt commented Feb 1, 2014

@syranide Heh, thanks for the reassurance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants