<?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>188284</bug_id>
          
          <creation_ts>2018-08-02 16:32:38 -0700</creation_ts>
          <short_desc>Custom elements created by the parser in a connected position have their constructors and connectedCallbacks called out of order</short_desc>
          <delta_ts>2018-08-14 15:36:34 -0700</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 11</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>188189</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=188327</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Russell Bicknell">bicknellr</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>bicknellr</cc>
    
    <cc>cdumez</cc>
    
    <cc>fred.wang</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1447431</commentid>
    <comment_count>0</comment_count>
      <attachid>346427</attachid>
    <who name="Russell Bicknell">bicknellr</who>
    <bug_when>2018-08-02 16:32:38 -0700</bug_when>
    <thetext>Created attachment 346427
A page with custom elements that log when their constructor and connectedCallback are called.

When a group of custom elements are created through the parser (either because they are in the main document&apos;s HTML or are in a string being set to a connected element&apos;s `innerHTML` property), they are all constructed before any have their `connectedCallback` called.

For example, for this tree:

&lt;c-e id=&quot;A&quot;&gt;
  &lt;c-e id=&quot;B&quot;&gt;&lt;/c-e&gt;
&lt;/c-e&gt;
&lt;c-e id=&quot;C&quot;&gt;&lt;/c-e&gt;

Safari calls the constructor and connectedCallback of each in this order:

- constructor A
- constructor B
- constructor C
- connectedCallback A
- connectedCallback B
- connectedCallback C

However, the order should be this:

- constructor A
- connectedCallback A
- constructor B
- connectedCallback B
- constructor C
- connectedCallback C


Relevant spec text:
https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token

The &apos;in-document HTML&apos; case would have &apos;will execute script&apos; set to true, meaning that the interleaved order above is the expected order, AFAICT.

I think Safari&apos;s `innerHTML` is correct here though: it would have &apos;will execute script&apos; set to false, so the connectedCallback reactions would all be delayed until they&apos;re popped at the end.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1447462</commentid>
    <comment_count>1</comment_count>
    <who name="Russell Bicknell">bicknellr</who>
    <bug_when>2018-08-02 17:22:26 -0700</bug_when>
    <thetext>Chrome and Firefox seem to have the opposite problem; their `innerHTML` setters act as if the elements being created were in the main document:
https://bugs.chromium.org/p/chromium/issues/detail?id=870512
https://bugzilla.mozilla.org/show_bug.cgi?id=1480632</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1447979</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-08-04 22:06:14 -0700</bug_when>
    <thetext>Do we have any WPT tests that cover these cases?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1447983</commentid>
    <comment_count>3</comment_count>
    <who name="Frédéric Wang Nélar">fred.wang</who>
    <bug_when>2018-08-05 00:44:47 -0700</bug_when>
    <thetext>For the synchronous case (&apos;in-document HTML&apos;), the patch on bug 188190 is supposed to force execution of the connectedCallBack immediately after insertion of the element (There is WPT test to ensure the element is indeed empty when connectedCallBack is called). That might improve things, but I don&apos;t know beforehand what we do regarding the order of constructor call / element insertion, especially since HTMLConstructionSite uses an m_taskQueue to delay insertion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1448252</commentid>
    <comment_count>4</comment_count>
    <who name="Russell Bicknell">bicknellr</who>
    <bug_when>2018-08-06 14:53:45 -0700</bug_when>
    <thetext>(BTW, the other two bugs I mentioned are now closed: my interpretation of the spec was wrong.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1448300</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-08-06 17:01:22 -0700</bug_when>
    <thetext>&lt;rdar://problem/42987289&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1448377</commentid>
    <comment_count>6</comment_count>
    <who name="Frédéric Wang Nélar">fred.wang</who>
    <bug_when>2018-08-07 00:56:30 -0700</bug_when>
    <thetext>(In reply to Russell Bicknell from comment #4)
&gt; (BTW, the other two bugs I mentioned are now closed: my interpretation of
&gt; the spec was wrong.)

Thanks for the update. For the non-synchronous case (innerHTML) note that bug 188327 was recently fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1450121</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2018-08-14 15:36:28 -0700</bug_when>
    <thetext>Okay, this is caused by the bug 188189 so I&apos;ll fix it there.

*** This bug has been marked as a duplicate of bug 188189 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>346427</attachid>
            <date>2018-08-02 16:32:38 -0700</date>
            <delta_ts>2018-08-02 16:32:38 -0700</delta_ts>
            <desc>A page with custom elements that log when their constructor and connectedCallback are called.</desc>
            <filename>safariCEParserCreatedOrder.html</filename>
            <type>text/html</type>
            <size>754</size>
            <attacher name="Russell Bicknell">bicknellr</attacher>
            
              <data encoding="base64">PCFkb2N0eXBlIGh0bWw+Cgo8c2NyaXB0PgpsZXQgb3JkZXIgPSAwOwpjbGFzcyBDRSBleHRlbmRz
IEhUTUxFbGVtZW50IHsKICBjb25zdHJ1Y3RvcigpIHsKICAgIHN1cGVyKCk7CiAgICB0aGlzLmF0
dGFjaFNoYWRvdyh7bW9kZTogJ29wZW4nfSkuaW5uZXJIVE1MID0gYAogICAgICBbPHNwYW4gaWQ9
ImxvZyI+PC9zcGFuPl0gPHNsb3Q+PC9zbG90PgogICAgYDsKICAgIHRoaXMuX2xvZyhgY29uc3Ry
dWN0b3IgJHtvcmRlcisrfWApOwogIH0KCiAgY29ubmVjdGVkQ2FsbGJhY2soKSB7CiAgICB0aGlz
Ll9sb2coYCwgY29ubmVjdGVkQ2FsbGJhY2sgJHtvcmRlcisrfWApOwogIH0KCiAgX2xvZyh0ZXh0
KSB7CiAgICB0aGlzLnNoYWRvd1Jvb3QucXVlcnlTZWxlY3RvcignI2xvZycpLmFwcGVuZENoaWxk
KG5ldyBUZXh0KHRleHQpKTsKICB9Cn0KY3VzdG9tRWxlbWVudHMuZGVmaW5lKCdjLWUnLCBDRSk7
Cjwvc2NyaXB0PgoKPGMtZT4KICA8Yy1lPgogICAgPGMtZT48L2MtZT4KICAgIDxjLWU+PC9jLWU+
CiAgPC9jLWU+CiAgPGMtZT4KICAgIDxjLWU+PC9jLWU+CiAgICA8Yy1lPjwvYy1lPgogIDwvYy1l
Pgo8L2MtZT4KPGMtZT4KICA8Yy1lPjwvYy1lPgogIDxjLWU+PC9jLWU+CjwvYy1lPgoKPHN0eWxl
PgpjLWUgewogIGRpc3BsYXk6IGJsb2NrOwogIG1hcmdpbjogMnB4OwogIGJvcmRlcjogMXB4IHNv
bGlkIGdyYXk7CiAgcGFkZGluZzogMnB4Owp9CgpjLWUgYy1lIHsKICBtYXJnaW4tbGVmdDogMmNo
Owp9Cjwvc3R5bGU+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>