| Summary: | document.adoptNode is a no-op when called on a template element's document fragment | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | huocp | ||||
| Component: | DOM | Assignee: | Ryosuke Niwa <rniwa> | ||||
| Status: | RESOLVED FIXED | ||||||
| Severity: | Normal | CC: | annevk, bigopon.777, cdumez, karlcow, m.goleb+bugzilla, rniwa, webkit-bug-importer | ||||
| Priority: | P2 | Keywords: | BrowserCompat, InRadar | ||||
| Version: | Safari 16 | ||||||
| Hardware: | All | ||||||
| OS: | Unspecified | ||||||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=204980 | ||||||
| Attachments: |
|
||||||
|
Description
huocp
2022-10-21 23:36:46 PDT
Found https://github.com/WebKit/WebKit/pull/2034 It's probably a changed behaviour following changed spec. Pls close it if this is not a bug. OK, I found an issue without involving adoptNode api. create a test.html file with following content <!doctype html> <html> <body> <template id="a"> <p>1</p> </template> </body> </html> Open it in Safari 16+. Try in console: > var d = document.querySelector('#a') < undefined > d; < <template id="a">…</template> > d.content < Template Content > d.content.ownerDocument < #document > d.content.ownerDocument.documentElement < null Should not every node in this static html file have ownerDocument pointing to the document itself?? The null ownerDocument.documentElement seems not right for the content of HTMLTemplateElement. (In reply to huocp from comment #2) > OK, I found an issue without involving adoptNode api. > > create a test.html file with following content > > <!doctype html> > <html> > <body> > <template id="a"> > <p>1</p> > </template> > </body> > </html> > > Open it in Safari 16+. > Try in console: > > > var d = document.querySelector('#a') > < undefined > > d; > < <template id="a">…</template> > > d.content > < Template Content > > d.content.ownerDocument > < #document > > d.content.ownerDocument.documentElement > < null > > Should not every node in this static html file have ownerDocument pointing > to the document itself?? > > The null ownerDocument.documentElement seems not right for the content of > HTMLTemplateElement. Please ignore my previous comment2, just found out all other browsers do the same. Created attachment 463188 [details]
testcase for adoptnode
Firefox and Chrome return an HTMLHtmlElement object
Safari returns `null`
There was recent changes to this code. 5 days ago. https://github.com/WebKit/WebKit/commit/ab3c0b8cf2a411231da9526614ad5167971dcdd5 Following a discussion on https://github.com/whatwg/dom/pull/819 There are 3 opened bugs for the spec change. https://bugzilla.mozilla.org/show_bug.cgi?id=1602200 https://bugs.webkit.org/show_bug.cgi?id=204980 https://bugs.chromium.org/p/chromium/issues/detail?id=1031811 This is intentional behavior change per https://github.com/whatwg/dom/pull/819 It has been noted that the approach in the web spec isn't "web compatible", and it shouldn't be implemented. A quick link https://github.com/whatwg/dom/pull/819#discussion_r1007199723 Can we please have this commit reverted? The discussion for the initial breakage is https://github.com/aurelia/framework/issues/1003 As of today https://bug-246899-attachments.webkit.org/attachment.cgi?id=463188 # STP 164 fragment.ownerDocument.documentElement: null Then document.adoptNode(fragment); fragment.ownerDocument.documentElement null # Firefox Nightly 112.0a1 (2023-03-02) fragment.ownerDocument.documentElement: null Then document.adoptNode(fragment); fragment.ownerDocument.documentElement [object HTMLHtmlElement] # Chrome Canary 113.0.5627.0 fragment.ownerDocument.documentElement: null Then document.adoptNode(fragment); fragment.ownerDocument.documentElement [object HTMLHtmlElement] We probably need to reverse this change and see if there is a path forward in the specification as being discussed in https://github.com/whatwg/dom/pull/819 I'm reopening the bug. Pull request: https://github.com/WebKit/WebKit/pull/11347 Committed 261491@main (dd0a5a2fd2e2): <https://commits.webkit.org/261491@main> Reviewed commits have been landed. Closing PR #11347 and removing active labels. |