Re: [css-houdini-drafts] [css-typed-om] Update CSSUnitValue not updating element style in Chrome (bug?) (#995)

This is working as intended. Having "live" values that implicitly update styles when they're changed is a pretty dangerous antipattern, for a few reasons:

* it makes perf much more difficult to manage, introducing more "pause while we restyle the world" cases unexpectedly. (For example, if you're updating both the X and Y coordinates of a CSSTransformValue object, is there any chance the page could restyle *after* you update X but *before* you update Y? Are you *sure*?)
* lifetimes for the objects become *very* tricky - what happens if the style gets updated underneath you? Is the object dead? How can you tell?
* what happens if you .set() one property's object onto another element/property?

Having the objects instead be "dead", so style only updates when you explicitly set them back to the style map, resolves all of these issues very simply.

> It makes so much sense for performance to be able to modify the objects in place without having to create new instances. If we have to create new instances in an animation loop (for example), it will create a needless amounts of garbage to be collected, which is most definitely not ideal.

As you noted in the followup comment, there's no need to `new` up values constantly; it's both allowed and *encouraged* to just reuse the same objects across multiple `.set()` calls, precisely for the perf reasons you mention.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/995#issuecomment-664703686 using your GitHub account

Received on Tuesday, 28 July 2020 00:17:32 UTC