<?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>20127</bug_id>
          
          <creation_ts>2012-11-28 18:58:05 +0000</creation_ts>
          <short_desc>[Templates]: Template needs to disallow DOM hierarchy cycles which can result from template.contents</short_desc>
          <delta_ts>2013-02-08 17:53:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</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>
          
          <blocked>15476</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Rafael Weinstein">rafaelw</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>adamk</cc>
    
    <cc>annevk</cc>
    
    <cc>dglazkov</cc>
    
    <cc>hsivonen</cc>
    
    <cc>travil</cc>
    
    <cc>tross</cc>
    
    <cc>wchen</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79028</commentid>
    <comment_count>0</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-11-28 18:58:05 +0000</bug_when>
    <thetext>e.g.

template.content.appendChild(template).

Note that ShadowRoot has an nearly identical problem, we hopefully we can address both with the same solution.

I propose the right behavior is DOM operation that would result in a cycle via template.content throw a DOM HIERARCHY exception the same way that it does now with parent/child cycles.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82101</commentid>
    <comment_count>1</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-01-24 17:54:24 +0000</bug_when>
    <thetext>This has been implemented both for template element and also for ShadowRoot in WebKit.

Note that I&apos;ve made a non-normative comment about this in the template element spec. I suspect that maybe DOM needs to say something about this, but I&apos;m not sure how to approach this.

Anne, what&apos;s your feeling?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82102</commentid>
    <comment_count>2</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-01-24 17:55:26 +0000</bug_when>
    <thetext>Note that last statement under the template element section:

https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#template-element</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82139</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-25 13:58:18 +0000</bug_when>
    <thetext>Lets keep this open until it&apos;s fixed then okay?

So it seems like in addition to checking the inclusive ancestors as is already done by the pre-insert and replace algorithms, we also need to check the inclusive ancestors of the object the tree is associated with.

Should we maybe introduce a new node that inherits from DocumentFragment that can carry that additional semantic as well as provide a pointer to the hosting element?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82159</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Klein">adamk</who>
    <bug_when>2013-01-25 20:02:29 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; Should we maybe introduce a new node that inherits from DocumentFragment
&gt; that can carry that additional semantic as well as provide a pointer to the
&gt; hosting element?

When you say &quot;provide a pointer&quot; do you mean as part of its interface? The WebKit implementation of course does exactly what you describe (a DocumentFragment subclass, a pointer to the host &lt;template&gt;) but doesn&apos;t change at the WebIDL level.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82191</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-26 08:42:57 +0000</bug_when>
    <thetext>Well the idea was a new interface as the functionality might be useful. But I guess for now I can add a concept to DocumentFragment named &quot;host&quot; and then add the appropriate checks to pre-insert and replace in case there&apos;s a DocumentFragment root which has a host defined. Would that work?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82242</commentid>
    <comment_count>6</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-01-28 20:47:59 +0000</bug_when>
    <thetext>@Anne, I like your solution in comment 5.

It seems like we should avoid exposing |host| as an IDL property until we have a clear use case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82275</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-29 12:36:42 +0000</bug_when>
    <thetext>If someone appends &lt;template&gt;.contents (or whatever that&apos;s called), that should just work right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82349</commentid>
    <comment_count>8</comment_count>
    <who name="Adam Klein">adamk</who>
    <bug_when>2013-01-30 20:50:30 +0000</bug_when>
    <thetext>(In reply to comment #7)
&gt; If someone appends &lt;template&gt;.contents (or whatever that&apos;s called), that
&gt; should just work right?

Yes, that&apos;ll simply remove everything from the content fragment and append it to wherever it got appended, as it works for any other fragment. But there&apos;s no way to &quot;detach&quot; the fragment from the &lt;template&gt; (its &quot;host&quot; property can&apos;t change).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82635</commentid>
    <comment_count>9</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-06 17:40:47 +0000</bug_when>
    <thetext>https://github.com/whatwg/dom/commit/bc62c366536ace9fde6bbc9f0098d0f17a64aef1
http://dom.spec.whatwg.org/#concept-documentfragment-host

You can now use this host concept in the &lt;template&gt; specification.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82653</commentid>
    <comment_count>10</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-06 22:26:24 +0000</bug_when>
    <thetext>@Anne: The language in pre-insert doesn&apos;t look sufficient to me. I think you need to recursively traverse host boundaries.

e.g.

&lt;div&gt;
  &lt;template&gt;
    &lt;div&gt;
      &lt;template&gt;

and append the outer div to the inner-most template.content.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82691</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-07 12:37:49 +0000</bug_when>
    <thetext>https://github.com/whatwg/dom/commit/534a39839a8bb69b6cf57c7692fe16ead5b1bcb7

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82716</commentid>
    <comment_count>12</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-07 21:34:26 +0000</bug_when>
    <thetext>Ok. The spec now is clear that when the content document fragment is initialized, its host element is set to the template.

https://dvcs.w3.org/hg/webcomponents/rev/1671f8bac2df

I&apos;m going to go ahead and close this and leave it to Anne to get the language correct in DOM about preventing hierarchy cycles.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82745</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-08 10:09:41 +0000</bug_when>
    <thetext>Are you saying I did not fix it? I&apos;m confused.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82771</commentid>
    <comment_count>14</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-08 17:53:53 +0000</bug_when>
    <thetext>My bad. I didn&apos;t noticed that you had fixed it. Looks right to me now. Thanks!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>