[w3c/webcomponents] Unexpected upgrade timing when appending an element and script together (#606)

**Expected behavior**
A fragment is appended to the document containing an upgradeable custom element candidate  followed by a script. The script should be able to act on the element in its upgraded state.

**Actual behavior**
The element is not upgraded when the script runs. 

**Example**
See http://jsbin.com/xesitet/edit?html,console,output.

**Discussion**
It seems like this behavior is probably [per current spec](https://html.spec.whatwg.org/multipage/scripting.html#custom-element-reactions) and Safari Tech Preview 17 and Chrome both exhibit the issue. However, the behavior was unexpected when we encountered it. It was discovered when trying to adapt the [HTMLImports polyfill](https://github.com/webcomponents/webcomponentsjs/tree/master/src/HTMLImports) to be compatible with Safari Tech Preview 17's implementation of custom elements. The polyfill appends fragments of imported dom that can contain custom elements and scripts together. After puzzling out the behavior for awhile we have a workaround that avoids the issue, but it was certainly very tricky to reason about.

**Proposed Fix**
Require the custom elements reaction stack be flushed before running script. 


-- 
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/606

Received on Friday, 11 November 2016 19:57:56 UTC