Closed Bug 1480632 Opened 6 years ago Closed 6 years ago

Custom elements created through setting innerHTML have callbacks called as if they were in the main document

Categories

(Firefox :: Untriaged, defect)

63 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: bicknellr, Unassigned)

Details

Attachments

(1 file)

Attached file ceInnerHTMLOrder.html
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36

Steps to reproduce:

1. Define a custom element that keeps track of the order of its constructor and `connectedCallback` calls.
2. Assign a string of HTML containing a few of the custom elements to `innerHTML` of some element that is connected to the document.


Actual results:

Each `connectedCallback` is called after the constructor and before the next constructor, as if the elements were not being created for the HTML fragment parsing algorithm.


Expected results:

`connectedCallback` of all of the custom elements should all be called in a group at the end of the set to `innerHTML`.

Relevant spec text:
https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token
https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions
https://w3c.github.io/DOM-Parsing/#dfn-innerhtml

AFAICT, setting `innerHTML` causes the "create an element for the token" algorithm to set the "will execute script" variable to false, meaning that the connectedCallback reactions enqueued by creating and appending elements in the fragment will be delayed until the set to `innerHTML` is over and the [CEReactions] attribute would cause the associated queue to be popped / flushed.
Safari has the opposite problem, it creates and calls `connectedCallback` on elements in the main document as if they were set with `innerHTML`:
https://bugs.webkit.org/show_bug.cgi?id=188284
Actually, I've been convinced that this behavior is correct: https://bugs.chromium.org/p/chromium/issues/detail?id=870512#c7 Sorry about spamming the queue!
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: