-
Notifications
You must be signed in to change notification settings - Fork 305
Make element and attribute names behave like the HTML parser #449
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
73602fa
to
d607808
Compare
Those are the variants you would actually use internally, as you don't want to use setAttribute() which is rather odd when it comes to namespaces.
HTML elements care too. Say more. |
What do you mean "internally"? Looking at e.g. Ember or React it seems like everyone branches on whether they're supplied a namespace by their caller (presumably only for SVG cases) and uses setAttribute instead. Anecdotally, I've never used setAttributeNS myself.
I would have thought that after all the trouble we went through to try to simplify Attrs, at least one of the changes that might have stuck was making their namespace APIs have no effect on the processing models that consult those attributes. I guess not. |
I mean browsers. Browsers definitely care about the namespace of an attribute. And the problem with |
I'm still a little unclear on what you mean by "care". They store it, so it can be reflected in other DOM APIs, sure. But e.g. if I set the Basically my confusion is about whether anyone ever cares about setting the namespace of an attribute "correctly", such as when trying to set two attributes with the same name but different namespace. It seems like the fact frameworks provide methods that take a namespace means some people care. I am not sure why, given my above example of browsers not caring about the namespace for |
Why do you think it should be the HTML namespace? (Hint: if you use the HTML namespace for the "src" attribute, it won't load.) |
Ah, very interesting. Browsing https://developer.mozilla.org/en-US/docs/Web/SVG/Namespaces_Crash_Course, it appears that people use namespaces for This makes me lean toward not caring about the -NS methods for attributes at all as people should mostly only have to use them for I guess that still leaves createElementNS though, and we maybe should make the attribute-NS methods consistent with that. So, what should our answer be for createElementNS? |
Given that |
My $0.02, I think you do want createElementNS to use the HTML rules for local names in the HTML namespace. Why? It would be good if there's one line of code authors can reliably use to duplicate an element. I think that line has to be:
(OK three lines. And a function, "magic", which somehow detects autonomous built-in elements and produces a dictionary with 'is' for them.) Maybe validate and extract step 5 should specify that it splits on the first colon. Since If you make the local name checks consistent with createElement's then that line of code should be sufficient for duplicating an element, whether it is HTML, SVG or vanilla. |
d607808
to
d91bdac
Compare
I've updated this with a revision that takes into account the -NS methods too. |
I have posted some data from Chromium here: https://bugs.chromium.org/p/chromium/issues/detail?id=648179&desc=2#c19 |
OK, so we finally have data!
Unfortunately, it looks like simply aligning with the HTML parser is not going to be possible. @dominiccooney mentioned it might be possible to change the parser to allow more, but in general that's pretty high-cost and risky. Unless there's some unexpected enthusiasm for that, I'd rather set it aside. What do people think of just expanding the valid-in-DOM category? Then we will still have two categories, but at least valid-in-DOM will be a superset of valid-in-HTML. I could work on updating this PR to illustrate that concretely, if people would like. |
I always thought that was the plan. With the syntax being less expressive. Matching the HTML exactly would never have worked due to casing depending on context and such. |
|
|
||
<li><p>If <var>qualifiedName</var> contains a "<code>:</code>" (U+003E), then split | ||
<var>qualifiedName</var> on that first occurrence of "<code>:</code>" and set <var>prefix</var> to | ||
the part before and <var>localName</var> to the part after. |
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.
@domenic before
and after
seem a bit vague. Perhaps suffix with ... _prefix
to the part before and localName
to the part after the :
respectively.
Just a thought. Sounded incomplete when reading out loud.
@dominiccooney has started gathering data on this in Blink, so I wanted to help the process along by preparing a spec PR. We should not merge this yet.
The biggest open question, which we could use some help on, is what to do with the -NS variants, createElementNS and createAttributeNS/setAttributeNS.
One idea I thought of is that "validate and extract" should delegate to the HTML validate-and-canonicalize algorithms if the namespace passed in is the HTML namespace.
Another idea is that we should just leave them alone. But I think the same frameworks that are asking for this change for HTML elements probably also want it for SVG elements. (I'm surprised SVG elements care what namespace their attributes are in...)
Note to self: we need to remember to also update the restrictions on valid custom element names, since they were designed to be the union of restrictions from the HTML parser + the DOM APIs.
💥 Error: 500 Internal Server Error 💥
PR Preview failed to build. (Last tried on Jan 15, 2021, 7:33 AM UTC).
More
PR Preview relies on a number of web services to run. There seems to be an issue with the following one:
🚨 CSS Spec Preprocessor - CSS Spec Preprocessor is the web service used to build Bikeshed specs.
🔗 Related URL
If you don't have enough information above to solve the error by yourself (or to understand to which web service the error is related to, if any), please file an issue.