<?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>23206</bug_id>
          
          <creation_ts>2013-09-11 04:31:56 +0000</creation_ts>
          <short_desc>[Custom]: The base element queue doesn&apos;t prevent custom element processing running ahead of imports</short_desc>
          <delta_ts>2013-09-11 21:11:45 +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>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>
          
          <blocked>14968</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Dominic Cooney">dominicc</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>93224</commentid>
    <comment_count>0</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2013-09-11 04:31:56 +0000</bug_when>
    <thetext>Maybe I just don&apos;t understand the set of related specs well enough, but I don&apos;t see anything which stops custom element processing in a given document running ahead of imports in that document. The base element queue is sorted, and things are enqueued in it in a certain order, but it is unclear given:

&lt;x-a&gt;
&lt;link rel=&quot;import&quot; href=&quot;two.html&quot;&gt;
&lt;x-b&gt;

two.html:
...
&lt;x-c&gt;
...

that x-a, x-b, x-c isn&apos;t a valid order provided that x-a, x-b are run at one microtask checkpoint and x-c is run at another.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93227</commentid>
    <comment_count>1</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2013-09-11 06:52:38 +0000</bug_when>
    <thetext>Here&apos;s a stab at a more operational algorithm that I think might be feasible:

There is a DOCUMENT QUEUE.

Each document has a BASE ELEMENT QUEUE.

When the parser pops an Custom Element, frazzle the element.

Additionally, when a &lt;link rel=&quot;import&quot; ...&gt; is inserted into a document, frazzle that element too.

To frazzle ELEMENT:

If ELEMENT&apos;s owner document is not in DOCUMENT QUEUE:
  Insert ELEMENT&apos;s owner document into DOCUMENT QUEUE
If ELEMENT is not in owner document&apos;s BASE ELEMENT QUEUE:
  Insert ELEMENT into owner document&apos;s BASE ELEMENT QUEUE

At a microtask checkpoint:

For each DOCUMENT in DOCUMENT QUEUE:
  If DOCUMENT &quot;is an import&quot;*:
    Skip DOCUMENT
  Otherwise:
    Process DOCUMENT&apos;s BASE ELEMENT QUEUE

* Being an import is a dynamic condition. If the &lt;link&gt; tag that begot you orphans you, you&apos;re not an import any more?

(I didn&apos;t do any DOCUMENT QUEUE emptying. The BEQs become empty so repeatedly processing them is a no-op. But an implementation would remove a document that has finished parsing from the DOCUMENT QUEUE.)

To process a BEQ:

For each ELEMENT in BEQ, in order:
  If ELEMENT is an IMPORT:
    If ELEMENT has an imported document:
      Process the ELEMENT&apos;s imported document&apos;s BEQ (ie recurse).
    If the ELEMENT&apos;s IMPORT READY FLAG is not set:
      Stop these steps. Commentary: Everything (including the link
      element) is left in BEQ for next time.
  Remove ELEMENT from the BEQ
  Process ELEMENT&apos;s associated CALLBACK QUEUE (if any)

Commentary:

There are complicating factors motivating this craziness:

- &lt;link rel=&quot;import&quot; ...&gt; can be inserted and removed, bringing multiple documents into existence as it does so (I think?) so we need the document queue as a catch-all to make sure we eventually start calling people&apos;s callbacks.

- &lt;link rel=&quot;import&quot; ...&gt; doesn&apos;t necessarily have an associated document, so we need to use the link tags themselves to keep track of things.

The ordering is going to be defined, but extremely wild, if you move a link tag (particularly to a different document.) The wildness if because we use a link tag to find a document to recurse to, but that might not be the one begotten from that insertion; time might have marched on? You get what you deserve.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93259</commentid>
    <comment_count>2</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-09-11 17:32:17 +0000</bug_when>
    <thetext>(In reply to Dominic Cooney from comment #0)
&gt; Maybe I just don&apos;t understand the set of related specs well enough, but I
&gt; don&apos;t see anything which stops custom element processing in a given document
&gt; running ahead of imports in that document. The base element queue is sorted,
&gt; and things are enqueued in it in a certain order, but it is unclear given:
&gt; 
&gt; &lt;x-a&gt;
&gt; &lt;link rel=&quot;import&quot; href=&quot;two.html&quot;&gt;
&gt; &lt;x-b&gt;
&gt; 
&gt; two.html:
&gt; ...
&gt; &lt;x-c&gt;
&gt; ...
&gt; 
&gt; that x-a, x-b, x-c isn&apos;t a valid order provided that x-a, x-b are run at one
&gt; microtask checkpoint and x-c is run at another.

You&apos;re right! If:

1) the queue is in this state: [ x-a, @, x-b ], where &quot;@&quot; is the import that has not loaded,
2) parser yields and the microtask checkpoint occurs,
3) the callbacks for x-a and x-b will be invoked, and x-c will be invoked later.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93271</commentid>
    <comment_count>3</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-09-11 21:10:05 +0000</bug_when>
    <thetext>(In reply to Dominic Cooney from comment #1)

In spec, I think I can express this in just a few sentences. Let me give it a shot.

&gt; Commentary:
&gt; 
&gt; There are complicating factors motivating this craziness:
&gt; 
&gt; - &lt;link rel=&quot;import&quot; ...&gt; can be inserted and removed, bringing multiple
&gt; documents into existence as it does so (I think?) so we need the document
&gt; queue as a catch-all to make sure we eventually start calling people&apos;s
&gt; callbacks.

Adding and removing import links imperative means that:
1) we&apos;re no longer operating on base element queue, and
2) all fetches are synchronous

This helps greatly, since this makes all these operations atomic and we don&apos;t need to worry about stability of order (or ordering at all).
 
&gt; - &lt;link rel=&quot;import&quot; ...&gt; doesn&apos;t necessarily have an associated document,
&gt; so we need to use the link tags themselves to keep track of things.
&gt; 
&gt; The ordering is going to be defined, but extremely wild, if you move a link
&gt; tag (particularly to a different document.) The wildness if because we use a
&gt; link tag to find a document to recurse to, but that might not be the one
&gt; begotten from that insertion; time might have marched on? You get what you
&gt; deserve.

I think it&apos;s same as above. I could be wrong. This is complicated stuff :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93272</commentid>
    <comment_count>4</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-09-11 21:11:45 +0000</bug_when>
    <thetext>https://dvcs.w3.org/hg/webcomponents/rev/ae75ca747696, WDYT?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>