News for hackers. Stuff that matters.
Re:Web Components Eliminate JavaScript Framework Lock-In by QuadmasterXLII on Monday November 27, 2023 @01:54PM (#38436532)
Can I borrow some knowledge? What sort of operations trigger a reflow and repaint?
Re:Web Components Eliminate JavaScript Framework Lock-In by lioeters on Monday November 27, 2023 @04:42PM (#38438809)
"Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout."

> What forces layout/reflow. The comprehensive list.

> All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

https://gist.github.com/paulirish/5d52fb081b3570c81e3a

Re:Web Components Eliminate JavaScript Framework Lock-In by nostrademons on Monday November 27, 2023 @03:52PM (#38438091)
Short answer: anything that modifies the DOM, followed by a call which measures geometric properties of the DOM. Also you get an automatic reflow/repaint when control leaves the Javascript event handler that triggers a modification (this is how the browser's UI is updated). You can batch up a bunch of modifications without triggering a reflow and then have it account for all of them on next reflow, though, which is what React tries to achieve with the Virtual DOM and what you get for free after ~2013.

Slightly longer answers:

[modifies] https://developers.google.com/speed/docs/insights/browser-re...

[measures] https://gist.github.com/paulirish/5d52fb081b3570c81e3a

Also there's a bunch of exceptions where you can modify things without triggering a full reflow. Anything that takes elements out of normal flow (position: fixed, position: absolute, float:, overflow: hidden) creates a layout boundary where changes inside only reflow the containing element. Any element with a transform: or opacity: property gets rendered as a 2D texture on the GPU, and then you can do subsequent transform/opacity animations purely on the GPU without touching the CPU. Used to do this to make performant animations on mobile devices.