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

LeaVerou left a comment (WICG/webcomponents#1029)

@DeepDoge 

> > 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".

Love this. I think it addresses all these issues brilliantly and is much simpler than anything proposed so far. 💯 
We could probably define similar semantics for other lifecycle callbacks (`disconnectedCallback`, `adoptedCallback` etc). It would be good to do a review of use cases to see how common it is to need lifecycle hooks around the element itself, that are separate from those of the attribute node. Though, assuming these are niche, they can always be addressed via `MutationObserver` improvements down the line (e.g. [connectedness is already an open feature request](https://github.com/whatwg/dom/issues/533))

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

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

Received on Tuesday, 2 December 2025 21:26:42 UTC