3 ms·
I've run into a pretty ridiculous Chrome bug: let f = document.createDocumentFragment(); f.appendChild(document.createElement("div")); f.firstChild.outer
by cxr 4y ago
I've run into a pretty ridiculous Chrome bug:
let f = document.createDocumentFragment();
f.appendChild(document.createElement("div"));
f.firstChild.outerHTML = (`<a href="https://bugs.chromium.org/"></a>`);
Fails because a fragment "is not an element node", a completely bogus error. No idea if it fails in Safari, too, since I don't have a Mac anymore, but I'd guess so, since this reeks of the type of corner-cutting that WebKit was guilty of while swimming in accolades for being a fast, standards-compliant browser engine (in contrast to e.g. Gecko).
- lapcat 4y ago> a completely bogus error How is it bogus? outerHTML is an attribute of Element https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML https://developer.mozilla.org/en-US/docs/Web/API/Element/out... and DocumentFragment is not an Element https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment https://developer.mozilla.org/en-US/docs/Web/API/DocumentFra... > No idea if it fails in Safari, too It does. Have you considered that it's just a Gecko quirk that it happens to work in Firefox? Where do the standards say it ought to work?
- cxr 4y ago> How is it bogus? outerHTML is an attribute of Element Re-read what is written. I'm setting the outerHTML property of an element, not setting it for the fragment (which is the only way that your response would make sense). > Have you considered that it's just a Gecko quirk that it happens to work in Firefox? No, because I'm not a moron. > Where do the standards say it ought to work? Exactly where you'd expect to find it: in the specification of the outerHTML property (Leithead et al. DOM Parsing and Serialization, Extensions to the Element interface, §7.1 Attributes: outerHTML. 2016.)
- lapcat 4y agoSee the Notes section of the docs: "If the element has no parent element, setting its outerHTML property will not change it or its descendants. Many browsers will also throw an exception." https://developer.mozilla.org/en-US/docs/Web/API/Element/outerHTML#notes https://developer.mozilla.org/en-US/docs/Web/API/Element/out... The div has a parent node but no parent element, because a document fragment is not an element.
- LegionMammal978 4y agoThe standard says that if the parent node is a DocumentFragment, then a temporary Element must be created to act as the context element for fragment parsing [0]. [0] https://www.w3.org/TR/2016/WD-DOM-Parsing-20160517/#widl-Element-outerHTML https://www.w3.org/TR/2016/WD-DOM-Parsing-20160517/#widl-Ele...
- lapcat 4y agoWell, if Mozilla's own web developer API documentation contradicts the spec here, then I'd say that none of the browser vendors are doing on good job on this particular issue.
- cxr 4y agoIt's documentation. It's describing the Blink/WebKit behavior and couching it in terms of what "many browsers" do—it's not saying what they should do; all you've done is linked to a page that says the bug exists. Nice try moving the goalposts, though. It has been a monumental waste of energy participating in this conversation.
- LegionMammal978 4y agoThat's not quite what it says; it says that (unconditionally) it will do nothing without a parent element and (conditionally, depending on the browser) it will throw an exception. The first part is inaccurate, since the standard behavior (which is the current behavior of Gecko and the intended behavior of Blink) is to let it work naturally on children of DocumentFragments. It should probably be updated to clarify this, but I wouldn't see the remark as very "normative" in the first place.
- cxr 4y agoWhat?
- 4y ago
- LegionMammal978 4y ago> Where do the standards say it ought to work? The wording has not changed since the 2016 version of the DOM Parsing and Serialization standard [0]: > On setting, the following steps must be run: 1. Let parent be the context object's parent. [...] 4. If parent is a DocumentFragment, let parent be a new Element with > - body as its local name, > - The HTML namespace as its namespace, and > - The context object's node document as its node document. But Blink instead throws a DOMException with name "NoModificationAllowedError" and message "Failed to set the 'outerHTML' property on 'Element': This element's parent is of type '#document-fragment', which is not an element node." This was filed as a Chromium bug last December and assigned a week later [1]. [0] https://www.w3.org/TR/2016/WD-DOM-Parsing-20160517/#widl-Element-outerHTML https://www.w3.org/TR/2016/WD-DOM-Parsing-20160517/#widl-Ele... [1] https://crbug.com/1403060 https://crbug.com/1403060