Re: [csswg-drafts] [cssom] `ComputedStyleObserver` to observe changes in elements' computed styles (#8982)

> if your observer is delayed by a microtask, it doesn't really get to prevent anything.

It's not going to prevent the recalc, but it's going to prevent the changes from being painted. I believe that's what one would want to prevent, I don't think one would want to prevent a recalc through this API, just like one doesn't prevent the mutation from happening in a MutationObserver. I guess my use of the word "preventing" is to blame here, "revert" is probably more what I had in mind.

Firing sync seems problematic because then you get outer scripts running in the middle of another script entirely, possibly causing many useless recalcs. For instance, one can assume that when they do trigger a full synchronous reflow in their code, they can continue requesting the computed styles again and again without triggering a new recalc (remember that it's the getters on the CSSStyleDeclaration that do trigger reflows, not to mention that the actual triggers [are numerous](https://gist.github.com/paulirish/5d52fb081b3570c81e3a)). Firing the observer's callback synchronously in the middle of it would cause yet another reflow at the next property read (and I guess prevent some code optimization).  

Firing it in its own step is also problematic since just like the CSS transition trick, it will inevitably miss changes that will end up painted. 

-- 
GitHub Notification of comment by Kaiido
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8982#issuecomment-2324615010 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 2 September 2024 12:16:11 UTC