<?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>23002</bug_id>
          
          <creation_ts>2013-08-18 20:44:35 +0000</creation_ts>
          <short_desc>Hoist &lt;template&gt; to head when found between &lt;/head&gt; and &lt;body&gt; for consistency with &lt;script&gt;</short_desc>
          <delta_ts>2013-10-10 00:38:08 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#the-after-head-insertion-mode</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>blocker</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          <blocked>23032</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>rafaelw</cc>
    
    <cc>travil</cc>
    
    <cc>tross</cc>
    
    <cc>w3c</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>92245</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-08-18 20:44:35 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html
Multipage: http://www.whatwg.org/C#the-after-head-insertion-mode
Complete: http://www.whatwg.org/c#the-after-head-insertion-mode
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/

Comment:
Hoist &lt;template&gt; to head?

Posted from: 90.230.218.37
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.49 Safari/537.36 OPR/16.0.1196.45 (Edition Next)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92246</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-08-18 20:45:43 +0000</bug_when>
    <thetext>[[
A start tag whose tag name is one of: &quot;base&quot;, &quot;basefont&quot;, &quot;bgsound&quot;, &quot;link&quot;, &quot;meta&quot;, &quot;noframes&quot;, &quot;script&quot;, &quot;style&quot;, &quot;title&quot;
]]

&lt;template&gt; isn&apos;t in this list. Shouldn&apos;t it be? For all elements that can appear in head we hoist it to head if it appears after &lt;/head&gt; but before the body.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92362</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-08-20 17:53:07 +0000</bug_when>
    <thetext>Rafael, any opinion?

Seems like something we should fix, to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92375</commentid>
    <comment_count>3</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-08-20 18:37:16 +0000</bug_when>
    <thetext>Just so I&apos;m clear, we&apos;re talking about how

&lt;head&gt;&lt;/head&gt;&lt;template&gt;

parses?

i.e. right now it will be

&lt;html&gt;
  &lt;head&gt;
  &lt;body&gt;
    &lt;template&gt;

and you&apos;re saying maybe it should be

&lt;html&gt;
  &lt;head&gt;
    &lt;template&gt;
  &lt;body&gt;

?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92376</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-08-20 19:05:28 +0000</bug_when>
    <thetext>Yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92378</commentid>
    <comment_count>5</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-08-20 19:16:58 +0000</bug_when>
    <thetext>I&apos;m not against it -- although I&apos;m a little fuzzy on what value it provides. Is it just consistency with elements which *can* appear in head...that we assume if they came after head but before body, we assume you meant head?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92381</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-08-20 19:33:55 +0000</bug_when>
    <thetext>Consistency with &lt;script&gt; et al, yeah.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92391</commentid>
    <comment_count>7</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-08-20 21:54:49 +0000</bug_when>
    <thetext>Meh. I&apos;ll let you guys decide. I&apos;m happy to make the change in blink - depending. 

Also, it&apos;s worth getting travis &amp; tony ross&apos;s opinion, but I think we&apos;ll need a w3c bug for that =-(.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92411</commentid>
    <comment_count>8</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-08-21 11:40:44 +0000</bug_when>
    <thetext>Made a clone https://www.w3.org/Bugs/Public/show_bug.cgi?id=23032

I don&apos;t know what their addresses in bugzilla are so I haven&apos;t cc-ed them.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92412</commentid>
    <comment_count>9</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2013-08-21 11:50:54 +0000</bug_when>
    <thetext>From #whatwg:

&lt;zcorpan&gt; hsivonen: do you have an opinion on the above bug?
&lt;hsivonen&gt; zcorpan: I don&apos;t care much either way, but it&apos;s weird not to be consistent with &lt;script&gt;. might be good to check with wchen.
&lt;zcorpan&gt; seems unlikely anyone will have a strong opinion on this :-P
&lt;jgraham&gt; I think &quot;just do it&quot; is the right approach. It doesn&apos;t seem like it should need explicit buy in from lots of people since it&apos;s such a small thing


I agree with jgraham.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92472</commentid>
    <comment_count>10</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-08-22 20:21:03 +0000</bug_when>
    <thetext>Tony, Travis, do you have any opinions on whether we should make this change?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92480</commentid>
    <comment_count>11</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2013-08-22 21:05:12 +0000</bug_when>
    <thetext>Replied in the other bug (in favor of this change).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93311</commentid>
    <comment_count>12</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-09-12 20:25:30 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8179.
Check-in comment: Have &lt;/head&gt;&lt;template&gt;&lt;/template&gt; go in the &lt;head&gt; for consistency with other elements.
http://html5.org/tools/web-apps-tracker?from=8178&amp;to=8179</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94049</commentid>
    <comment_count>13</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-09-30 23:33:13 +0000</bug_when>
    <thetext>Ok. Sorry, I&apos;m just now getting around to trying to implement this in blink, and there&apos;s a problem here.

consider:

&lt;head&gt;&lt;/head&gt;&lt;template&gt;

This example actually breaks the current parser (as spec&apos;d).

-The &lt;template&gt; is now handled by &quot;after head&quot; which pushes the &lt;head&gt; back on, processes the &lt;template&gt; for &quot;in head&quot;, then pops the &lt;head&gt; off.
-EOF is reached, which processes a fake &quot;&lt;/template&gt;&quot;, which pops the &lt;template&gt; off and
-resets the insertion mode appropriately

The problem here is that &quot;reset the insertion mode&quot; is going to inspect the bottom-most element on the stack which is now &lt;html&gt; and it will set the mode to &quot;before head&quot;.

Nothing good happens after this.

Unless someone has a simple fix for this that I&apos;m missing, I&apos;m inclined to back out this spec change and just live without &lt;template&gt; getting hoisted into &lt;head&gt; if it appears immediately after &lt;/head&gt;. I think the benefit is questionable and the problem it&apos;s causing is fairly bad.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94095</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-01 17:51:01 +0000</bug_when>
    <thetext>That example is fine since it&apos;s an EOF, nothing happens.

But it&apos;s true that &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;template&gt;&lt;/template&gt;&lt;head&gt; ends up crazy.

We could handle this by having the reset algorithm check if the head element pointer is set, and if so, go to after head instead of before head, I think.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94096</commentid>
    <comment_count>15</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-01 18:00:06 +0000</bug_when>
    <thetext>Is there any where else in the parser that we make decisions about parsing based on state in the document (as opposed to the stack of open elements)?

My mental model is that the parser operates on an incoming stream and the stack of open elements (whose elements may or may not, at any given time, still be in the document they started in).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94109</commentid>
    <comment_count>16</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-01 20:28:53 +0000</bug_when>
    <thetext>What do you consider making a decision about parsing based on the state in the document here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94128</commentid>
    <comment_count>17</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-01 23:08:30 +0000</bug_when>
    <thetext>checking the head element pointer. are we sure we&apos;ll always check the *right* document?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94206</commentid>
    <comment_count>18</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-02 21:01:58 +0000</bug_when>
    <thetext>The head element pointer is parser state, not document state. It&apos;s similar to the form element pointer.

   http://whatwg.org/html/#the-element-pointers

Does that change your conclusion?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94208</commentid>
    <comment_count>19</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-02 21:08:57 +0000</bug_when>
    <thetext>I guess it&apos;s no grosser than it already is (because in order to do this we push that head pointer element onto the stack).

Adding adam since he shared my reluctance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94209</commentid>
    <comment_count>20</comment_count>
    <who name="Adam Barth">w3c</who>
    <bug_when>2013-10-02 21:10:47 +0000</bug_when>
    <thetext>We should test this case too:

&lt;body&gt;&lt;/body&gt;&lt;template&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94211</commentid>
    <comment_count>21</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-02 21:28:22 +0000</bug_when>
    <thetext>@adam: &lt;body&gt;&lt;/body&gt;&lt;template&gt; is fine since AfterBody  defers to InBody for &quot;anything else&quot; (and &lt;/body&gt; doesn&apos;t pop the &lt;body&gt; element), but I&apos;ve added a test to html5lib in blink (which I&apos;ll shortly upstream).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94257</commentid>
    <comment_count>22</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-03 19:00:49 +0000</bug_when>
    <thetext>So should I try doing what comment 14 suggests?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94260</commentid>
    <comment_count>23</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-03 19:04:08 +0000</bug_when>
    <thetext>Let me try it blink before you spend time on specing it. I&apos;ll post the patch here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94443</commentid>
    <comment_count>24</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-08 03:09:50 +0000</bug_when>
    <thetext>Ok, this has landed in blink as https://src.chromium.org/viewvc/blink?revision=159064&amp;view=revision.

Note that the above change implies not only the current language in &quot;After Head&quot; which includes &quot;template&quot; amongst the start tags which are hoisted into &lt;head&gt;, it also implies:

-Reset the insertion mode appropriate, step 3 should no longer be marked as &quot;fragment case&quot;

-Reset the insertion mode appropriately, step 15 should check the head element pointer, switching to &quot;After Head&quot; if it is set and &quot;Before Head&quot; if not, and aborting the steps in either case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94524</commentid>
    <comment_count>25</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-10-09 22:33:42 +0000</bug_when>
    <thetext>Ok. Done. Let me know if I missed anything.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94525</commentid>
    <comment_count>26</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-10-09 22:35:06 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8218.
Check-in comment: Update the HTML parser to handle &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;template&gt;&lt;/template&gt;&lt;!----&gt;
http://html5.org/tools/web-apps-tracker?from=8217&amp;to=8218</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94527</commentid>
    <comment_count>27</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-10-09 23:10:34 +0000</bug_when>
    <thetext>lgtm</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>