<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>246899</bug_id>
          
          <creation_ts>2022-10-21 23:36:46 -0700</creation_ts>
          <short_desc>document.adoptNode is a no-op when called on a template element&apos;s document fragment</short_desc>
          <delta_ts>2023-03-10 00:31:18 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari 16</version>
          <rep_platform>All</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=204980</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>huocp</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>annevk</cc>
    
    <cc>bigopon.777</cc>
    
    <cc>cdumez</cc>
    
    <cc>karlcow</cc>
    
    <cc>m.goleb+bugzilla</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1907505</commentid>
    <comment_count>0</comment_count>
    <who name="">huocp</who>
    <bug_when>2022-10-21 23:36:46 -0700</bug_when>
    <thetext>Safari 16+ (including 16.1 beta and Safari Technology Preview) seems didn&apos;t assign ownerDocument correctly in DOM api document.adoptNode.
Reproducible on both mac and iPhone.

In Safari 16+ browser console, reproduce it with following code:
&gt; const div = document.createElement(&apos;div&apos;)
div.innerHTML = &apos;&lt;template&gt;&lt;p&gt;&lt;/p&gt;&lt;/template&gt;&apos;;

const fragment = div.firstChild.content;
&lt; &quot;&lt;template&gt;&lt;p&gt;&lt;/p&gt;&lt;/template&gt;&quot;
&gt; fragment.ownerDocument.documentElement
&lt; null
&gt; document.adoptNode(fragment);
&lt; Document Fragment
&gt; fragment.ownerDocument.documentElement
&lt; null

In comparison, in other browser (Chrome, Firefox or older Safari), the ownerDocument is assigned after adoptNode.

&gt; const div = document.createElement(&apos;div&apos;)
div.innerHTML = &apos;&lt;template&gt;&lt;p&gt;&lt;/p&gt;&lt;/template&gt;&apos;;

const fragment = div.firstChild.content;
&lt; &apos;&lt;template&gt;&lt;p&gt;&lt;/p&gt;&lt;/template&gt;&apos;
&gt; fragment.ownerDocument.documentElement
&lt; null
&gt; document.adoptNode(fragment);
&lt; #document-fragment
&gt; fragment.ownerDocument.documentElement
&lt; &lt;html ...&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1907583</commentid>
    <comment_count>1</comment_count>
    <who name="">huocp</who>
    <bug_when>2022-10-22 15:47:40 -0700</bug_when>
    <thetext>Found https://github.com/WebKit/WebKit/pull/2034

It&apos;s probably a changed behaviour following changed spec. Pls close it if this is not a bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1907622</commentid>
    <comment_count>2</comment_count>
    <who name="">huocp</who>
    <bug_when>2022-10-23 02:32:54 -0700</bug_when>
    <thetext>OK, I found an issue without involving adoptNode api.

create a test.html file with following content

&lt;!doctype html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;template id=&quot;a&quot;&gt;
&lt;p&gt;1&lt;/p&gt;
&lt;/template&gt;
&lt;/body&gt;
&lt;/html&gt;

Open it in Safari 16+.
Try in console:

&gt; var d = document.querySelector(&apos;#a&apos;)
&lt; undefined
&gt; d;
&lt; &lt;template id=&quot;a&quot;&gt;…&lt;/template&gt;
&gt; d.content
&lt; Template Content
&gt; d.content.ownerDocument
&lt; #document
&gt; d.content.ownerDocument.documentElement
&lt; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1907623</commentid>
    <comment_count>3</comment_count>
    <who name="">huocp</who>
    <bug_when>2022-10-23 02:40:24 -0700</bug_when>
    <thetext>(In reply to huocp from comment #2)
&gt; OK, I found an issue without involving adoptNode api.
&gt; 
&gt; create a test.html file with following content
&gt; 
&gt; &lt;!doctype html&gt;
&gt; &lt;html&gt;
&gt; &lt;body&gt;
&gt; &lt;template id=&quot;a&quot;&gt;
&gt; &lt;p&gt;1&lt;/p&gt;
&gt; &lt;/template&gt;
&gt; &lt;/body&gt;
&gt; &lt;/html&gt;
&gt; 
&gt; Open it in Safari 16+.
&gt; Try in console:
&gt; 
&gt; &gt; var d = document.querySelector(&apos;#a&apos;)
&gt; &lt; undefined
&gt; &gt; d;
&gt; &lt; &lt;template id=&quot;a&quot;&gt;…&lt;/template&gt;
&gt; &gt; d.content
&gt; &lt; Template Content
&gt; &gt; d.content.ownerDocument
&gt; &lt; #document
&gt; &gt; d.content.ownerDocument.documentElement
&gt; &lt; null
&gt; 
&gt; Should not every node in this static html file have ownerDocument pointing
&gt; to the document itself??
&gt; 
&gt; The null ownerDocument.documentElement seems not right for the content of
&gt; HTMLTemplateElement.

Please ignore my previous comment2, just found out all other browsers do the same.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1907731</commentid>
    <comment_count>4</comment_count>
      <attachid>463188</attachid>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-10-23 23:14:59 -0700</bug_when>
    <thetext>Created attachment 463188
testcase for adoptnode

Firefox and Chrome return an HTMLHtmlElement object
Safari returns `null`</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1907735</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2022-10-23 23:46:27 -0700</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1908223</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-10-25 13:52:38 -0700</bug_when>
    <thetext>This is intentional behavior change per https://github.com/whatwg/dom/pull/819</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1936333</commentid>
    <comment_count>7</comment_count>
    <who name="">bigopon.777</who>
    <bug_when>2023-02-23 14:05:32 -0800</bug_when>
    <thetext>It has been noted that the approach in the web spec isn&apos;t &quot;web compatible&quot;, and it shouldn&apos;t be implemented. A quick link https://github.com/whatwg/dom/pull/819#discussion_r1007199723

Can we please have this commit reverted?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1938393</commentid>
    <comment_count>8</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-03-02 19:52:58 -0800</bug_when>
    <thetext>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&apos;m reopening the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1940313</commentid>
    <comment_count>9</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2023-03-09 22:41:13 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/11347</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1940325</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-03-10 00:30:13 -0800</bug_when>
    <thetext>Committed 261491@main (dd0a5a2fd2e2): &lt;https://commits.webkit.org/261491@main&gt;

Reviewed commits have been landed. Closing PR #11347 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1940326</commentid>
    <comment_count>11</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-03-10 00:31:18 -0800</bug_when>
    <thetext>&lt;rdar://problem/106542160&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>463188</attachid>
            <date>2022-10-23 23:14:59 -0700</date>
            <delta_ts>2022-10-23 23:14:59 -0700</delta_ts>
            <desc>testcase for adoptnode</desc>
            <filename>adoptnode-test-case.html</filename>
            <type>text/html</type>
            <size>1126</size>
            <attacher name="Karl Dubost">karlcow</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KICA8aGVhZD4KICAgIDxtZXRhIGNoYXJz
ZXQ9IlVURi04IiAvPgogICAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250
ZW50PSJJRT1lZGdlIiAvPgogICAgPG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRo
PWRldmljZS13aWR0aCwgaW5pdGlhbC1zY2FsZT0xLjAiIC8+CiAgICA8dGl0bGU+ZG9jdW1lbnQu
YWRvcHRub2RlPC90aXRsZT4KICA8L2hlYWQ+CiAgPGJvZHk+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ZW50LmRvY3VtZW50
RWxlbWVudDt9CgogICAgPC9zY3JpcHQ+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>