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

Boolean attributes no longer coerced to string #9779

Closed
wants to merge 3 commits into from

Conversation

klinsley
Copy link

From #9230, this abides by the HTML5 spec mentioned in the issue. This issue was left in an unsure state and I wanted to try my first contribution.

@aweary
Copy link
Contributor

aweary commented May 29, 2017

I think I would be OK with this, semantically speaking it's correct for boolean attributes, and practically speaking I believe it will maintain the same behavior.

cc @spicyj what do you think?

} else if (value === true) {
node.setAttribute(name, '');
} else if (value === false) {
node.removeAttribute(name);
Copy link
Contributor

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, where null is used to identify attributes that should be removed.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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 🤔

Copy link
Contributor

@syranide syranide May 29, 2017

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.

Copy link
Contributor

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.

DOMPropertyOperations.setValueForProperty(stubNode, 'data-foo', false);
expect(stubNode.getAttribute('data-foo')).toBe(null);
});

Copy link
Contributor

Choose a reason for hiding this comment

The 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:

https://codepen.io/nhunzaker/pen/YVoYMV?editors=1010

Copy link
Contributor

Choose a reason for hiding this comment

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

That is correct; DOMStringMap (the backing type for .dataset) always only holds string values.

@gaearon
Copy link
Collaborator

gaearon commented Jan 5, 2018

I'm closing since this is stale and there was no consensus. Appreciate the PR!

@gaearon gaearon closed this Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants