Re: [WICG/webcomponents] Proposal: Custom attributes for all elements, enhancements for more complex use cases (Issue #1029)

DeepDoge left a comment (WICG/webcomponents#1029)

> does connectedCallback() fire when the attribute is connected, or when the element is connected?

I don't know if my opinion matters here, but:

IMO custom attributes are composable behavior units, kind of like a superset of extended custom elements. So, `connectedCallback()` should run only when both are true:
- The attribute is attached to an element
- That element is connected to the DOM

If we simply it even more, it should trigger when the attribute is connected to the DOM, not when attribute is connected to an element.

Just like how a custom element's `connectedCallback()` gets triggered when the element is actually connected to the DOM, not when it has a parent.

The whole point of `connectedCallback()` / `disconnectedCallback()` is to initialize or clean things up depending on whether the thing (element or attribute) is live in the DOM.

So should it be called "when the attribute is connected, or when the element is connected?": 
It should be called when the attribute is connected to the DOM, which also requires element its connect to be connected to the DOM as well. I think we can all agree that "Connected" means "Connected to the DOM".

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1029#issuecomment-3599188181
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1029/3599188181@github.com>

Received on Monday, 1 December 2025 22:14:28 UTC