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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>17529</bug_id>
          
          <creation_ts>2012-06-18 07:13:09 +0000</creation_ts>
          <short_desc>Inserting multiple script elements using a document fragment isn&apos;t specified properly</short_desc>
          <delta_ts>2013-03-22 00:10:27 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>HTML5 spec</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>17530</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Olli Pettay">bugs</reporter>
          <assigned_to name="Silvia Pfeiffer">silviapfeiffer1</assigned_to>
          <cc>annevk</cc>
    
    <cc>contributor</cc>
    
    <cc>hsivonen</cc>
    
    <cc>ian</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>travil</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>69189</commentid>
    <comment_count>0</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-06-18 07:13:09 +0000</bug_when>
    <thetext>Per HTML spec inserting script element to DOM should execute it immediately
(I&apos;m talking about var s = document.createElement(&quot;script&quot;); s.textContent = &quot;alert(&apos;foo&apos;)&quot;; document.body.appendChild(s); case)

Unfortunately it isn&apos;t clear what should happen when you have several
script elements in a document fragment and insert that document fragment to DOM.

Gecko seems to execute scripts after all the nodes are in DOM.
This seems to be ok per spec, since nothing prevents to do 
&quot;HTML: An element is said to have been inserted into a document when its root element changes and is now the document&apos;s root element.&quot; atomically for several elements and DOM4 just says
&quot;Insert all nodes in nodes before child or at the end of parent if child is null.&quot;
The behavior Gecko has doesn&apos;t cause problems to Mutation Record creation.

Presto and Webkit execute scripts one by one during the document fragment insertion
but not in the same way. Webkit seems to remove nodes first from the document fragment,
Presto removes them one by one. (Webkit&apos;s follow the spec here)
Anyhow, the tricky thing is that what if some script moves nodes during insertion.
What kinds of Mutation Records should be created? What should actually happen to the nodes
which are being inserted to DOM but which some script moves to elsewhere just before insertion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69220</commentid>
    <comment_count>1</comment_count>
    <who name="Henri Sivonen">hsivonen</who>
    <bug_when>2012-06-19 07:15:30 +0000</bug_when>
    <thetext>When there are nested scripts in the fragment, WebKit and IE10 agree on the execution order. Gecko doesn&apos;t. Presto misbehaves by using the .textContent instead of the concatenation of child text nodes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69222</commentid>
    <comment_count>2</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-06-19 08:21:00 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; When there are nested scripts in the fragment, WebKit and IE10 agree on the
&gt; execution order. Gecko doesn&apos;t. Presto misbehaves by using the .textContent
&gt; instead of the concatenation of child text nodes.
This bug isn&apos;t about nested scripts ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69261</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2012-06-19 23:27:42 +0000</bug_when>
    <thetext>We should absolutely not run scripts half-way through the mutation when a fragment is inserted. That brings back all the same trouble we had with mutation events.

The only sane thing, IMO, is to do all the mutations, and then do all actions which needs to synchronously call out into Javascript, and then return to the caller.

Anything else is both hellish to implement, and dramatically increases the amount of edge cases that we need to define (where does insertion happen if nodes are moved around half-way through the mutation, what happens if more nodes are added to the fragment as nodes are moved out of it, what happens if a child was removed from the fragment, but is inserted there again before the UA inserts it at its new location, and so on)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69262</commentid>
    <comment_count>4</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-06-19 23:30:35 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; We should absolutely not run scripts half-way through the mutation when a
&gt; fragment is inserted. That brings back all the same trouble we had with
&gt; mutation events.

Yup. I fully agree with you.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69310</commentid>
    <comment_count>5</comment_count>
    <who name="Henri Sivonen">hsivonen</who>
    <bug_when>2012-06-21 06:33:30 +0000</bug_when>
    <thetext>In addition to a document fragment, the same rules should apply even when inserting multiple elements at one by inserting an element that has element descendants.

About the execution order:
The parser executes scripts not in the depth-first order of start tags but in the depth first order of end tags. Of course, we don&apos;t have to be consistent with that, but worth remembering anyway.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69312</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-06-21 06:37:27 +0000</bug_when>
    <thetext>Yeah, this isn&apos;t defined.

Unless there&apos;s a compat reason not to, my inclination is to define execution as
happening after the mutation listeners, in tree order (pre-order, depth-first
traversal).

See also bug 17543.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69916</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-07-12 19:43:14 +0000</bug_when>
    <thetext>(this will probably use the hook from bug 17530)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70231</commentid>
    <comment_count>8</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 07:11:13 +0000</bug_when>
    <thetext>This bug was cloned to create bug 17880 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74152</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-20 19:50:00 +0000</bug_when>
    <thetext>*** Bug 17543 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84811</commentid>
    <comment_count>10</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2013-03-22 00:10:27 +0000</bug_when>
    <thetext>This was fixed by a previous commit:
https://github.com/w3c/html/commit/6afe9c0f52fc4ffc27be7a6c724ec0dd36877c5c</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>