TAMULib / weaver-components

Custom Web Components for the Weaver UI
MIT License
0 stars 1 forks source link

Performance Problems with getComputedStyle() (Layout Thrashing). #480

Open kaladay opened 3 years ago

kaladay commented 3 years ago

Tthe getComputedStyle() ends up forcing a layout redraw / reflow, see:

In testing this really seems to happen on calls to getPropertyValue() as seen here:

Consider the strategy from the referenced issues:

- Don't call getComputedStyle as much as possible.
- Don't call it in a loop (multiple force render.)
- If you have to have do it.
  a. do it at the debounce & after request animation frame. (Thus blink is already eval most of the data that you ask for.)
  b. stamp the class that you are looking for rather than ask the style to get for it.

Not to mention, according to the specs (https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) the values may be intentially incorrect.

...Returned values are sometimes deliberately inaccurate. To avoid the “CSS History Leak” security issue, browsers may lie about the computed styles for a visited link, returning values as if the user never visited the linked URL...