Bug 163147

Summary: importNode from template doesn't instantiate custom element
Product: WebKit Reporter: Jan Miksovsky <jan>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, rniwa
Priority: P2    
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 154907    

Description Jan Miksovsky 2016-10-07 15:10:27 PDT
See http://jsbin.com/tukocup/1/edit?html,console.

    class TestElement extends HTMLElement {}
    customElements.define('test-element', TestElement);

    let template = document.createElement('template');
    template.innerHTML = `<test-element></test-element>`;
    let clone = document.importNode(template.content, true);
    let element = clone.querySelector('test-element');
    console.log(element instanceof TestElement); // true in Chrome Canary, false in WebKit

This defines a custom element, then tries to use it in a template. Following the importNode call, the test-element node should be an instance of TestElement, but it's not. (It works as expected in Chrome Canary.)
Comment 1 Ryosuke Niwa 2016-10-07 23:46:48 PDT
This is kind of expected right now because we don't fully implement custom elements reactions yet.
Comment 2 Jan Miksovsky 2016-10-10 09:13:04 PDT
Ah, okay, we hadn't seen a description of what was/wasn't implemented. If such a description is posted somewhere, that would help us determine what bugs should be reported. Or should we just back off on reporting bugs for the time being?
Comment 3 Ryosuke Niwa 2016-10-10 19:08:44 PDT
(In reply to comment #2)
> Ah, okay, we hadn't seen a description of what was/wasn't implemented. If
> such a description is posted somewhere, that would help us determine what
> bugs should be reported. Or should we just back off on reporting bugs for
> the time being?

I'm actively fixing this but expect that no custom element reaction would fire beyond handful of DOM functions like appendChild, setAttribute, cloneNode, etc...
Comment 4 Ryosuke Niwa 2016-10-10 21:50:20 PDT
Oh actually, this behavior is expected. You need to insert the imported node into a document since upgrading now happens when an element is connected, not when it's instantiated.
Comment 5 Ryosuke Niwa 2016-10-11 00:51:29 PDT
On my second thought, we should probably just fix the spec so that this case works.
Comment 6 Ryosuke Niwa 2016-10-19 00:22:08 PDT
This has been fixed in https://trac.webkit.org/changeset/207170.