A history of how code transformation has affected the industry. And how it led to changes in how we write CSS
This talk has been presented at React Day Berlin 2024, check out the latest edition of this React Conference.
A history of how code transformation has affected the industry. And how it led to changes in how we write CSS
This talk has been presented at React Day Berlin 2024, check out the latest edition of this React Conference.
StylX is a tool for generating atomic CSS, maintained by Naman at Meta.
Early CSS lacked namespaces and variables, making it difficult to maintain and requiring repeated code.
CSS preprocessors like Sass and Less introduced features such as variables, nesting, and loops, improving CSS maintainability and functionality.
The community developed CSS modules and CSS in JS to address namespacing and scaling issues, with each approach offering different solutions and benefits.
Atomic CSS breaks styles into small, reusable pieces, maximizing reusability and scalability. It helps keep CSS size manageable as applications grow.
Tailwind CSS uses atomic styles to create a single small CSS file for the entire application, minimizing the need for lazy loading and improving performance.
While both generate atomic CSS, Tailwind works with almost any language and encourages repetition, while StylX is a JavaScript compiler that promotes reusability and is strongly typed.
React Strict DOM is a project that builds on StyleX to provide a common baseline for writing UI across web and React Native, offering web-like APIs that are not global.
Compilers have facilitated advancements in web development by enabling features like atomic CSS, improving performance, and enhancing developer experience.
Initially, web styling relied solely on HTML with limited capabilities like blink and marquee tags. CSS was later introduced to solve styling limitations, offering more power and reusability.
Hello, I'm Naman. Today, I'm going to talk about atomic power and the story of StylX. In the beginning, there was only HTML without CSS. We used blink tags and marquee tags for styling, which was limited. Then CSS was invented, solving some problems but creating new ones. CSS preprocessors like Sass and Less emerged to address these challenges.
Hello, I'm Naman. I maintain StylX at Mera, and today I'm going to talk about atomic power. And not the nuclear kind, but I'm going to talk about atomic, and I'm going to talk about power. And then using that lens, I'm going to tell you about the story of StylX.
So let's get started from the very beginning. In the beginning, there was HTML and it was the birth of the World Wide Web. And there was no CSS. HTML is all we had. And with that HTML, we used blink tags and marquee tags for some fun, font tags for some styling, and we dealt with table layouts too. That was not fun. This wasn't great, but it was very limited. All kinds of layouts that we do today were simply impossible. And it was very tedious. There was no way to reuse our styles across components. Components didn't even exist yet.
And so in a few years, smart people got together and invented CSS. CSS solved some of our biggest problems with styling in HTML. It was way more powerful, there were actual layouts you could do, and not just with tables. And it was way more reusable. You could define a CSS selector once and use it all over your HTML. But as we solved some problems, we discovered new ones. And we realized that since CSS had no namespaces, it was really difficult to maintain. And since this is early CSS, it didn't even have variables. So we don't have to repeat ourselves in our HTML, but now we have to repeat ourselves in our CSS.
So some more smart people got together, and we came up with a new set of tools. This time, they were CSS preprocessors. Things that would process something you wrote and generate your CSS. You may have heard of Sass and Less. I used to use Stylus, and CSS was CSS in JS before CSS in JS. CSS preprocessors solved some of our biggest problems with CSS, such as variables and nesting.
In the next era, there was a fork in the road. Some moved towards CSS modules, while others moved towards CSS in JS. CSS modules solved namespacing, but had scaling issues. CSS in JS provided namespacing and better developer experience. Compiled time CSS in JS evolved, solving some problems but not all scaling issues. The idea of atomic CSS emerged as a convergence between CSS modules and compile-time CSS in JS.
They also added a bunch of other powerful features like loops and includes. But they still didn't have namespacing, and it was still hard to maintain at scale. And so, engineers kept working. And in the next era, there was a fork in the road. And some of the community moved towards CSS modules, and another part of the community moved towards CSS in JS. The reason that this happened was because this is the era when single-page applications were becoming popular, and frameworks like React had started to come out. And just to be clear, there were many people who didn't move to either of these new tools and continued to use good old CSS or CSS preprocessors. But I'm going to be focusing on every step forward that we take and not continue to keep mentioning that, yes, the old tools never went away.
So, over on the CSS module side, it finally solved namespacing. This was huge. This is why CSS modules is so successful. But it was still hard to scale in some ways. In general, code maintainability had been solved for the most part, but you could still run into some amount of CSS conflicts, and your CSS bloat would continue to bloat as your application gets bigger. On the other hand, CSS in JS gave us namespacing as well, and it gave us a whole bunch of other powers. It gave us much better developer experience than anything we had tried before. You could now write your style in the same file as your markup, in the same file as your component. But most of these early CSS and JS libraries had really bad performance because they relied on runtime style injection. And so JavaScript developers, being JavaScript developers, we kept at it.
A bunch of really impressive libraries came and became successful. And eventually we reached the next milestone, which was compiled time CSS in JS. This was an evolution of the CSS in JS idea, where you don't have the performance overhead because you compile all of your CSS at build time, and you don't have any runtime-style injection anymore, but you still have the same great developer experience, which is why CSS in JS was so successful in the first place. And while it solved so many problems, it did not completely solve all of the scaling problems that we've had with basically every CSS solution we've ever tried. As your application gets bigger, your CSS gets bigger. Then you're forced to lazy-load your CSS, which means your page updates get slower because you're waiting on additional CSS to load and process and compute. And so we continued on. A bunch of more great compile-time CSS in JS libraries came out, like Linarea and Vanilla Extract, and we hit some kind of convergence, where the two streams kind of agreed on the idea of atomic CSS. Of course, not everyone agreed. Many people stuck to CSS modules, Vanilla CSS modules, and many others continued to use the compile-time CSS in JS, or even runtime CSS in JS. But it is important to note that a lot of people from both streams did agree that atomic CSS was a good idea. But what is atomic CSS? As soon as the term is mentioned, this thought pops in everyone's head, this elephant in the room.
We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career
Comments