Browsers are evolved to parse CSS separately from Javascript parsing, why are we trying to deviate from this and fit all in Javascript?
When you mix both Javascript and HTML (namely JSX) and then also CSS (JSS or another), you make your component a solid module that fits into a single file. You don't need to keep styles in a separate file anymore.
Then, the functional magic happens: as JSX is a pure function of raw data that returns "HTML" (not really), the same way CSS-in-JS is a pure function or raw data that returns "CSS" (also not really). From this point, I think it's worth reading about JSX and also about CSS-in-JS.
Styled-component CSS ships its javascript library to the client end, which actually parses styles at the runtime and put inside <style />
tag when each component loads on demand. This means extra load and logic eventually contributing to execution cycles on browser.
Not only on the run-time. Because CSS-in-JSS is just a function of data that returns CSS, you can use it on any platform. Take Node, add SSR, and you have style
elements delivered to the browser in response body, therefore parsed just like it would happen in the original case of getting CSS delivered.
Why need this?
Because it is convenient in development, just like React or Redux, just like jQuery, and just like any other lib, it comes at network load and browser performance cost.
You take a library because it solves a problem. If there seems to be no problem, why use library at all, right?
Does continuous computed style text banging via <style />
in the head tag cause browser reflow/repaint ?
There are so many things that force reflow.
Browsers are smart. They don't even make an attempt to repaint if the styles haven't changed. Which doesn't mean that they don't calculate the difference, which costs CPU time.
There's a good intro into the scope and complexity of style (re)calculations, it's really worth reading to understand the subject deeper.