-
Notifications
You must be signed in to change notification settings - Fork 295
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
setAttributeNode should not change order of existing attributes #116
Comments
That's probably doable. It adds more complexity into what is already a fairly complex codepath, unfortunately... |
Is the Gecko implementation pretty much step-by-step identical to the spec? If so I can see why it would complicate matters. In Blink there's first a search for the internal index of the attribute to replace, so the structure is quite different. |
The Gecko implementation is pretty much step by step identical to the spec, with the additional complication that Attr nodes are not what's stored in the element's list. They are reified as needed; the actual thing stored in the list is just the name and value. So there is some additional complication in terms of keeping the Attr nodes and actual attributes in sync. I think we could add a replace thing on top of all that stuff, though. |
Right, that's the same as in Blink, and I assume every browser engine ever. I did try to change Blink to be a step-by-step copy of the spec's algorithm, and that was how I discovered this issue. I think it would work fine, but it seems faster to converge on what Blink/Edge/WebKit already do. |
So what kind of mutation record should replacing give? The same as remove/append does today? Do we really want to create special code paths just for |
Judging only by the code, I think it would do the same as when That's not perfect. It would be weird that you can replace the Attr node, but for mutation observers it would look like the attribute has changed, which shows that Attr isn't actually the internal representation. |
I think that is fine personally, since mutation observers do not treat attributes as proper objects. However, I'm still wondering why we'd want to introduce this additional complexity for such an unused method. I guess because three out of four browsers already do it... |
When I filed this bug I was thinking of the difficulty of getting this fixed in three browser engines, but setAttributeNode and many other attribute-related methods need to be changed to get the case sensitivity in line with the spec, so perhaps this is a small concern in comparison. As for complexity, it looks like it doesn't matter much either way in Blink, so if replacing is actually a complication for Gecko and if it doesn't sit too well with the spec, then I just might change my mind on this. If so we should ask WebKit and Edge folks if they see any problem. |
(Maybe supply a nice summary of the issue for the people you just tagged in? What are the two behaviors, what are the practical web-facing differences, which browsers do what?) FWIW I find the spec/Gecko's behavior a decent bit less convoluted, and would kind of prefer it as such. But I am sympathetic to the shortest path to interop... |
The issue is whether or not Aside from that there's a question that if we do go with the former, what the mutation observer behavior should be. And it sounds like it should be the same as that of changing an attribute's value. |
You beat me to it, but this is what I was writing: The order of attributes can be observed in the
The spec and Gecko do option 1. Blink, Edge and WebKit do option 2. It's unlikely that there's any compatibility risk here, it's rather a matter of getting to an interoperable state and forgetting about these APIs. |
This also affects @smaug----, concerns? |
Judging from servo/servo#9061 (comment) all browsers have a "replace" algorithm here and issue a single mutation record. Gecko just implements the replacing via remove/append, whereas everyone else does an actual replace. Given that we should just do the replacing thing. Adjusting @nox' PR will get us there. |
Fixed through #139. |
https://dom.spec.whatwg.org/#concept-element-attributes-set
Per spec, this will remove oldAttr and append the new attr. This matches Gecko, but not Blink or Edge in this test:
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3758
Here is the same test using
setAttribute
, where the attribute order does not change:http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3759
This could be fixed by having the concept of replacing attributes, in addition to append/remove.
CC @bzbarsky @Ms2ger
The text was updated successfully, but these errors were encountered: