-
Notifications
You must be signed in to change notification settings - Fork 636
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
[cssom] ComputedStyleObserver
to observe changes in elements' computed styles
#8982
Comments
It would be quite useful to use this to reflect css state (combination of media/preference/container query and :hover/:focus etc) back into js by observing a custom property. Currently those either need to be tracked in parallel in the js (makes it hard to change anything) or handled entirely in js and have the js reflect the changes to css by adding and removing classes (annoying since it would be much easier to express in css) |
I guess simple cases could be covered by the already approved #6205? element.firstChild.matchContainer("style(property: value)")).addListener(listener) But yeah not the best API if the element doesn't have children or for properties with a non-trivial value space. |
ComputedStyleObserver
to observe changes in elements' computed styles
Here's a related issue describing a problem that would need to be solved for The more of these we add (which I think would be super useful) the more this problem will become pronounced. Adding Alternatively |
+1 for this proposal. |
We need an API to observe computed style changes.
One example use case is to update canvas rendering based on changes in computed styles of an element (f.e.
transform
values to determine where to draw things in a canvas).This would be generally useful for implementing things that CSS cannot do, or making early polyfills of new CSS features that haven't landed in browsers yet.
What could it look like? Taking a note from existing observers:
Some things like callback timing need to be ironed out. Maybe its timing would be aligned with animation frames like ResizeObserver.
Existing ideas and conversation:
The main take aways from these are:
While we're making a new API, we can also see about avoiding the same problem that ResizeObserver has:
The problem is that rendering loops typically redraw in animation frame callbacks, but if CSS style change callbacks run after rAF, rendering can be delayed and incorrect and it isn't obvious why.
Maybe the initial set of callbacks for change entries should fire before rAF? Giving typical rendering setups a chance to usually be correct and only sometimes needing an additional next frame for cases when a frame changes style. I'm not totally sure what the solution should be, but it has been a pain debugging these sorts of issues.
The text was updated successfully, but these errors were encountered: