[w3c/webcomponents] connectedCallback timing when the document parser creates custom elements (#551)

>From [a blink bug](http://crbug.com/639847), an author reported that `connectedCallback` is called too early in Blink.

```
<script>customElements.define('x-x', ...);
<script>customElements.define('y-y', ...);
<x-x>
  <div></div>
  <y-y></y-y>
</x-x>
```
or [a sample code in jsfiddle](https://jsfiddle.net/mcd7bd82/).

When current Blink impl runs this code, `this.children.length` is 1 in `connectedCallback` for `x-x`. This looks like matching to the spec to me, but I appreciate discussion here to confirm if my understanding is correct, and also to confirm if this is what we should expect.

My reading goes this way:

1. The parser is in [the "in body" insertion mode].
2. It sees `x-x` as **Any other start tag**, it [insert an HTML element].
3. [insert a foreign element] says to [create an element for a token], then insert.
Note that this "insert" is not a link, but I assume this is [insert a node]?
4. In [insert a node], step 5.2.1 enqueues `connectedCallback`.
5. In [enqueue a custom element callback reaction], it adds to the backup element queue.
6. The parser then reads `div`. In its [create an element for a token], _definition_ is null, so _will execute script_ is false. This `div` is then inserted.
7. The parser then reads `y-y`. In its [create an element for a token], _definition_ is non-null, so _will execute script_ is true.
8. Step 6.2 perform a microtask checkpoint if _will execute script_ is true, so the `connectedCallback` runs here.

Am I reading the spec correctly? If so, is this what we should expect?

@domenic @dominiccooney @rniwa 

[create an element for a token]: https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token
[enqueue a custom element callback reaction]: https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-callback-reaction
[insert a node]: https://dom.spec.whatwg.org/#concept-node-insert
[insert a foreign element]: https://html.spec.whatwg.org/multipage/syntax.html#insert-a-foreign-element
[insert an HTML element]: https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element
[the "in body" insertion mode]: https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/551

Received on Tuesday, 23 August 2016 05:17:30 UTC