Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[custom-elements] Why is attributeChangedCallback synchronous? #963

Open
trusktr opened this issue Jul 31, 2022 · 2 comments
Open

[custom-elements] Why is attributeChangedCallback synchronous? #963

trusktr opened this issue Jul 31, 2022 · 2 comments
Labels

Comments

@trusktr
Copy link
Contributor

trusktr commented Jul 31, 2022

Why is attributeChangedCallback synchronous despite the fact that DOM MutationEvents were removed because they were synchronous and deemed to be a bad thing?

So, in effect, attributeChangedCallback restores the "bad" nature of DOM MutationEvents: 1000 custom elements with attributeChangedCallbacks is essentially equivalent to 1000 elements with DOMAttrModified events, yet this has not been considered a bad thing in the case of custom elements.

Perhaps there are a few questions here actually:

  • Why is it ok for custom elements to have synchronous events and not for DOM MutationEvents?
  • Why don't we make attributeChangedCallback async like MutationObserver?
  • Why didn't we fix MutationEvents then? For example, we could have easily made MutationEvents fire "batched" in a microtask, or fire for specified attributes only as in el.addEventListener('DOMAttrModified:some-attribute', ...) or something.
@rniwa rniwa added the question label Jul 31, 2022
@rniwa
Copy link
Collaborator

rniwa commented Jul 31, 2022

Please follow discussion starting at https://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0297.html

In particular, you may find this response useful:
https://lists.w3.org/Archives/Public/public-webapps/2014JanMar/0316.html

@trusktr
Copy link
Contributor Author

trusktr commented Aug 30, 2022

That still doesn't explain why CE reactions are sync and MO are async, when in the end, they effectively achieve the same thing but from different perspectives (first person vs third person).

The real reason I wonder about this is ultimately because one paradigm (MutationObserver reactions) are incredibly and unnecessarily more complicated than the others (CustomElement reactions and DOM Mutation events).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants