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

Use lower case for HTML attributes #11110

Closed
wants to merge 3 commits into from

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Oct 5, 2017

It doesn't really matter because HTML is case insensitive but people prefer it.
Fixes #10863.

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 5, 2017

Also verified the attribute table hasn’t changed.

@gaearon gaearon mentioned this pull request Oct 5, 2017
19 tasks
var propertyInfo = DOMProperty.getPropertyInfo(name);
if (propertyInfo) {
if (shouldIgnoreValue(propertyInfo, value)) {
return '';
}
var attributeName = propertyInfo.attributeName;
if (namespace === HTML_NAMESPACE) {
attributeName = attributeName.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this happen once, when the properties are injected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That wouldn't help with properties that aren't in the whitelist.

Copy link
Contributor

Choose a reason for hiding this comment

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

But line 93 ensures that this code only runs when we have property info (which I believe is always from the whitelist)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I see. I guess we should update the custom ones too in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait. Why is this necessary? This already gets lower cased in the injection here:
https://github.com/facebook/react/blob/master/src/renderers/dom/shared/DOMProperty.js#L83

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like tests pass when I remove this statement! (98-100). Totally need the toLowerCase below though.

Copy link
Contributor

@nhunzaker nhunzaker left a comment

Choose a reason for hiding this comment

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

Looks good, but if we can run toLowerCase when we inject property info ahead of time, that could be nice. That might require passing the namespace into the injection function, or specifying it in the injections themselves.

@reactjs-bot
Copy link

reactjs-bot commented Oct 5, 2017

Deploy preview ready!

Built with commit 850550c

https://deploy-preview-11110--reactjs.netlify.com

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 5, 2017

I'm still not super sure it's worth it. I wonder if we can measure perf impact somehow.

@nhunzaker
Copy link
Contributor

@gaearon I wonder what it would take to more easily measure that sort of thing. We have the benchmarks, but do they cover SSR? @aickin did some work here. I wonder if we could adopt some of it.

Still it intuitively doesn't seem substantial.

@syranide
Copy link
Contributor

syranide commented Oct 6, 2017

Isn't it better to warn instead? It avoids confusion and possible spreading headaches.

<div fooBar={1} {...{foobar: 2}} />

But I'm guessing there's more to it than that.

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 6, 2017

It's mostly about lower casing supported attributes.

@sebmarkbage
Copy link
Collaborator

If this is meant for supported attributes, I think we should only do it for them. Since those are a few special cases we can compare them using interned strings (which we probably do in some places anyway?) and omit the same lower-cased interned string for each match instead of calling toLowerCase.

For custom ones we could warn but might be excessive since there might be custom ones where this is legit (although probably not).

@syranide
Copy link
Contributor

@sebmarkbage https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts

Any namespace-less attribute that is relevant to the element's functioning, as determined by the element's author, may be specified on an autonomous custom element, so long as the attribute name is XML-compatible and contains no ASCII upper alphas. The exception is the is attribute, which must not be specified on an autonomous custom element (and which will have no effect if it is).

So with the exception of namespaced attributes, custom elements may not use upper-case characters either.

@gaearon gaearon mentioned this pull request Oct 11, 2017
16 tasks
@cosmicdreams
Copy link

Do the conflicting files mean this work needs to be rebased? Sorry, new to this.

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 6, 2017

Yes. But we also haven't decided if we actually want to do this.

@gaearon
Copy link
Collaborator Author

gaearon commented Jan 5, 2018

Meh. What we're doing is technically correct. If somebody feels strongly about the output they can prettify it themselves. In practice it doesn't matter, and we don't want to take any potential perf hit there. If someone feels strongly you're welcome to provide real-world measurements demonstrating this patch has no effect on perf.

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.

None yet

7 participants