Open Bug 1666972 Opened 4 years ago Updated 3 years ago

Child custom-element connected callback executed before constructor

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 83
defect

Tracking

()

People

(Reporter: christian, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

Attached file ff test.zip

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0

Steps to reproduce:

If you create a parent custom element and a child derived from it and in the parent constructor you append that element to another container the child connected callback is called before the child constructor is executed.
Simple example attached.

Actual results:

You get errors on any access to the child custom element properties because they're not being created yet.

Expected results:

Before firing the connected callback the child constructor must be executed, that is what happens in all other browsers.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

John, I think you did some custom elements work. Mind taking a look?

Flags: needinfo?(jdai)

Sure, I will take a look. Keep NI for tracking.

Attached file test.htm

I suspect we run the reactions in a different order than Chrome. John, could you check what does the spec say about this case, i.e. what is the result of running the spec steps. Thanks.

Per comment 3, I can reproduce this bug by upgrading elements after their creation.

Here is Firefox output:
parent connected true
parent constructor
child connected true undefined
parent constructor
child constructor

Here are Chromium and Safari output:
parent constructor
parent connected true
parent constructor
child constructor
child connected true true

Status: UNCONFIRMED → NEW
Ever confirmed: true

To be more specific, the test script enqueue a connected callback reaction during running the constructor (from the appendChild call), and we seem to execute the callback reaction in appendChild's CEReaction, but Chrome runs the callback reaction after construct one, I think Chrome's behavior makes more sense, given it doesn't mix the reaction execution order, but I wonder what spec says about this case, i.e. does spec define something to prevent this kind of recursion case?

Attached file test2.htm

Simpler test case.

The tricky part is the upgrade and connected callback reaction are enqueued into the same element queue. And the same element queue would be pushed and popped to stack multiple times, we need to check the spec algorithm to see how do the reactions be executed.

I checked the spec, spec seems not to define something to defer the reactions executed,

so the next thing we need to check is whether we push the reaction to the element's reaction queue in the order defined in the spec.

May need more spec clarity.

Severity: -- → S3
Flags: needinfo?(jdai)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: