<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vlad Karnauch on Medium]]></title>
        <description><![CDATA[Stories by Vlad Karnauch on Medium]]></description>
        <link>https://medium.com/@vlad.karna?source=rss-fd21a603fca0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0buGmG8NTTmy2vzB3P14tA.jpeg</url>
            <title>Stories by Vlad Karnauch on Medium</title>
            <link>https://medium.com/@vlad.karna?source=rss-fd21a603fca0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:05:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vlad.karna/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Codux (by Wix) Case study: How we built The Elements Tree Panel]]></title>
            <link>https://medium.com/wix-engineering/codux-by-wix-case-study-how-we-built-the-elements-tree-panel-d1952ff8808e?source=rss-fd21a603fca0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1952ff8808e</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[codux]]></category>
            <category><![CDATA[ast]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ide]]></category>
            <dc:creator><![CDATA[Vlad Karnauch]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 07:07:17 GMT</pubDate>
            <atom:updated>2023-02-19T09:32:15.654Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Codux (by Wix) Case study: How we built The Elements Tree Panel: Architecture, technologies, and implementation.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsA7fs_5GgPeaG19_eWDKw.png" /><figcaption>Tree and Co-Ducks, Image by Midjourney</figcaption></figure><h3>Integrated Development Environment</h3><p>The term “Integrated Development Environment” was coined in the early 1970s to describe a single program that combines authoring, modifying, compiling, deploying, and debugging software.</p><p>Integrating these capabilities into a single program allowed for many innovations down the road, such as Syntax Highlighting, Code Completion, Type Checking; but above all: it made software flexible because it closed a feedback loop: developers could type in a command and see the result right away.</p><h3>Codux</h3><p><a href="http://codux.com/">Codux</a> is a visual IDE for React made by Wix. It displays your components on the stage, in the middle of the screen, so you can what you’re working on while coding. Put another way: Codux closes the feedback loop for React developers by integrating rendering into the IDE.</p><figure><img alt="Building Codux in Codux" src="https://cdn-images-1.medium.com/max/1024/1*iU8yVB84udvdmuaWBbSFzA.png" /><figcaption>Building Codux in Codux</figcaption></figure><p>Integrating rendering with the rest of the traditional IDE features has enabled a bunch of innovations and productivity improvements. I’m very proud to have been the lead developer on one of these innovations — <strong>The Elements Tree</strong>, and I want to share how we built it: its architecture, the technologies used, and some of the insights behind it.</p><h3>The Elements Tree</h3><p>The elements Tree visualizes the structure of your app, helping devs with several things:</p><ul><li>It makes it easier to <strong>understand the structure of your app</strong>, kinda like syntax highlighting on steroids.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*RZjSZli7OfVkIlpRZBbFAw.png" /><figcaption>This is the Elements Tree for the HelloWorld component below:</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6384345edac9c885907da5219315fd42/href">https://medium.com/media/6384345edac9c885907da5219315fd42/href</a></iframe><ul><li>Every row in the elements tree represents a sub-structure in your code; clicking it will allow you to edit it in other panels. For example, you could select a &lt;span&gt;to change its font-size.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*c89h8bFNywKczLXuyFJA5w.png" /><figcaption>This is the Elements Tree for the Condition component below</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70f41ac7ecb7f93e2c479342962c0b07/href">https://medium.com/media/70f41ac7ecb7f93e2c479342962c0b07/href</a></iframe><ul><li>It allows you to make <strong>visual changes</strong>, for example: you can drag a &lt;br/&gt; into the &lt;Layout&gt; components’ content property, drag it into an map(x =&gt; y) expression, or delete it altogether.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpWjoQ1jOno4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpWjoQ1jOno4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b41bb0125c6cf7b2400eb01a0e654060/href">https://medium.com/media/b41bb0125c6cf7b2400eb01a0e654060/href</a></iframe><h3>Architecture</h3><p>The Elements Tree is a good case study to explain how exactly this integration works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHqJBwG7Nx8d4XKYKFUoIQ.jpeg" /></figure><p>Codux reads files from your filesystem and parses your code into a Typescript AST data structure. Next, Codux runs a few transformers that add useful metadata to the runtime code. Finally, Codux renders* your code and displays it on the “Stage” in the middle of the screen.</p><p>*Obviously, rendering requires compiling, building, and bundling — very cool stuff, but outside the scope of this article.</p><p>The Elements Tree has three main inputs, represented by the blue boxes in the diagram.</p><ul><li>TypeChecker provides types for arguments, component properties, variables, consts, function return values, and everything else that can be typed.</li><li>Typescript AST — is a tree data structure representing your code. AST stands for Abstract Syntax Tree.</li><li>React devtools provides a FiberNode structure, representing what has been rendered on the Stage.</li></ul><p>The Elements Tree has one main output: The ASTModification API, I’d say it is the key for visually editing code. It is responsible for applying various modifications to the AST, such as: adding a component, removing an expression, or passing a value into a property. Once a modification is applied, Codux generates new code to reflect the change on your filesystem.</p><p>Let’s dive into each of these in more detail:</p><h3>Technologies and Implementation</h3><h4><strong>Abstract Syntax Tree (AST) in Typescript</strong></h4><p>An Abstract Syntax Tree (AST) is a data structure representing a program’s code. ASTs are essential for working with code. More info in the Wikipedia article <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">here</a>. It allows Codux to do several things:</p><h4><strong>Code Analysis</strong></h4><p>Typescript provides great tools to create syntax trees directly from code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8c9e43c69c0e6ea9065ac9bccdd0de2/href">https://medium.com/media/b8c9e43c69c0e6ea9065ac9bccdd0de2/href</a></iframe><p>sourceFile is a parsed AST; it is of type ts.SourceFile, extending ts.Node, which represents a node in the syntax tree. To traverse the tree, we can use node.forEechChild. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bc863ac227ca31fa5fb5c6aebef215d/href">https://medium.com/media/5bc863ac227ca31fa5fb5c6aebef215d/href</a></iframe><p>This is a recursive structure, and you can call childNode.forEachChild.</p><p>Every node has a .kind property, which lets you identify it with a corresponding type guard. For example, once we call ts.isJsxElement(node)<strong><em>, </em></strong>typescript identifies that <strong><em>node</em></strong>’s type is ts.JsxElement allows you to use properties unique to this type, such as .openingElement<strong><em> </em></strong><em>and </em>.tagName<em>. </em>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0b31d5baef7e62a07172621c1eecf9f/href">https://medium.com/media/a0b31d5baef7e62a07172621c1eecf9f/href</a></iframe><p>findRootJsx will traverse the nodes until it finds a <strong><em>ts.JsxElement</em></strong> and return its tagName, and position. node.forEachChild function will return whatever its’ callback will return. This code logs <strong>{ tagName: ‘h1’, from: 127, to: 160 }.</strong></p><h4><strong>Modification</strong></h4><p>Modifying your code is relatively straightforward. You can parse the code into a ts.sourceFile<strong><em>, </em></strong>then every ts.node<strong><em> </em></strong><em>inside </em>has a node.getStart() and node.getEnd()<strong><em> </em></strong>methods that can help us find the exact position in the sourceText string. We can replace in these positions with anything else. However, there is a better way.</p><p>It would be simpler and less prone to errors to modify the syntax tree and let Typescript handle the changes to the actual code. Transformers are the tool for that.</p><h4><strong>Transformers</strong></h4><p>A Transformer is a function that transforms a given ts.Node, changing it in some way. For example: let’s say we want a transformer to replace all &lt;h1&gt;s with &lt;b&gt;<em>s </em>to make titles bold.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d557c372b487e9f59f0b94059a6e9b77/href">https://medium.com/media/d557c372b487e9f59f0b94059a6e9b77/href</a></iframe><p>will become ➡️</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75af83b406b4dc42303f179b8404dd36/href">https://medium.com/media/75af83b406b4dc42303f179b8404dd36/href</a></iframe><p>to do that, we first need a ts.TransformerFactory object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0be203e40843159f35a413e405a17976/href">https://medium.com/media/0be203e40843159f35a413e405a17976/href</a></iframe><p>Next, to find the ones we want to transform we need to iterate all the nodes in sourceFile, we can use ts.visitEachChild<strong><em>:</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26fc87b0fa4885a8d0fb5736be4f0d54/href">https://medium.com/media/26fc87b0fa4885a8d0fb5736be4f0d54/href</a></iframe><p>Now that we’ve found the jsxElement, we want to check that it’s an &lt;h1&gt;:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dd5c811b371ebe2c9a52e6789a232e0/href">https://medium.com/media/1dd5c811b371ebe2c9a52e6789a232e0/href</a></iframe><p>Finally, we want to replace the &lt;h1&gt; tag with found with a &lt;b&gt; tag:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a01825ffac4588a99b09411d78277786/href">https://medium.com/media/a01825ffac4588a99b09411d78277786/href</a></iframe><p>That’s it! To see the result, we apply the transformer and print the result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85f311546691fe7218bc37f2a444d490/href">https://medium.com/media/85f311546691fe7218bc37f2a444d490/href</a></iframe><p>The log would display:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c29371172246851aebb0c977897e4b75/href">https://medium.com/media/c29371172246851aebb0c977897e4b75/href</a></iframe><p>These are very powerful tools, but so far, we haven’t seen anything new — traditional IDEs can analyze code and transform it; in fact, linters have taken advantage of these and similar tools since the 70’s when scientists were writing C code in Bell Labs. It is time to see how Codux integrates these tools with rendering.</p><h4>React devtools</h4><p>To understand what was rendered and visualize the structure of your app the Elements Tree employs React devtools. For example, check out the ColorfulList component below and its’ Elements Tree:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d79768763af85de3fd0b91971e8bd31/href">https://medium.com/media/4d79768763af85de3fd0b91971e8bd31/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*cBpGZHkjCBIqqowsW7uUqg.png" /><figcaption>Elements Tree for the ColorfulList component above.</figcaption></figure><p>The {items.map(…)}function is represented by the green lane (with the square on top) inside the div.root. <br>The recurring {item.emoji}and {item.title}expressions are represented by grey lanes. Because Codux renders your code, the Elements Tree can display all of the items, with their respective .emoji and .title values.</p><p>React’s devtools are open source and can be found <a href="https://github.com/facebook/react/tree/main/packages/react-devtools-core">here</a> and <a href="https://github.com/facebook/react/tree/main/packages/react-devtools-inline">here</a>; the inlined version requires simple initialization, this has to happen <em>before</em> importing react</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a2460c167f60a889f84327f06cd3bbb/href">https://medium.com/media/2a2460c167f60a889f84327f06cd3bbb/href</a></iframe><p>after calling initialize(window), react-devtools provides a very useful hook to listen to rendering events:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88b5c4694e502a65dd9c226754b39945/href">https://medium.com/media/88b5c4694e502a65dd9c226754b39945/href</a></iframe><p>To see what was rendered, react also provides a Fiber structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45e124d3a01cb9febe71903cd4429cbe/href">https://medium.com/media/45e124d3a01cb9febe71903cd4429cbe/href</a></iframe><p>This is very cool stuff: the Fiber structure contains all sorts of goodies: keys, elementType (React component or an element (&lt;div<strong><em>&gt;</em></strong>, &lt;img /&gt;, etc.), props, and just about everything you might want to know about the rendered result. You can, and should definitely, check all that out in the Fiber definition <a href="https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactInternalTypes.js">here</a>.</p><p>Every Fiber represents a react component, fragment, HTML element, or a text. Fibers are a singly linked list tree structure, meaning that every Fiber in the tree has a link to its’ closest sibling and its’ child. This structure is more space-efficient in memory, but it has implications for traversal. You can read more about it in the Wikipedia article <a href="https://en.wikipedia.org/wiki/Left-child_right-sibling_binary_tree">here</a>.</p><p>Finally, to understand where exactly in the code each Fiber originates, Codux transpiles the code with transformers, adding information that helps figure out which exact file/component/expression/loop/condition/variable/const/string created the Fiber, or in other words: Codux modifies the code, adding hints that later map each Fiber to a node in the code syntax tree.</p><h3>How it all comes together for the user</h3><p>In the video below, you can see the ColorfulList component from before, notice how each of the rendered items appears on the Elements Tree. In addition, all the items originate from a singleitems.map(...) function, so the Elements Tree displays them inside a green lane representing the map function (we call it a “repeater”).</p><p>In other words: to visualize the component, the Elements Tree integrates the code, and the rendered result. Also, If you watch the video to the end, you can see that Codux “undetstands” each item, and can edit the specific classNames applied to it, I’ll leave this to another Article.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/613eedc56cceb51faa2b06eababf4e3f/href">https://medium.com/media/613eedc56cceb51faa2b06eababf4e3f/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-wkItdHW2Qc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-wkItdHW2Qc&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8c6ea7950eca75e6a331ceaa3005464/href">https://medium.com/media/c8c6ea7950eca75e6a331ceaa3005464/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1952ff8808e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wix-engineering/codux-by-wix-case-study-how-we-built-the-elements-tree-panel-d1952ff8808e">Codux (by Wix) Case study: How we built The Elements Tree Panel</a> was originally published in <a href="https://medium.com/wix-engineering">Wix Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Future of CSS]]></title>
            <link>https://medium.com/wix-engineering/the-future-of-css-1764e9766875?source=rss-fd21a603fca0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1764e9766875</guid>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[css-modules]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vlad Karnauch]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 12:32:50 GMT</pubDate>
            <atom:updated>2022-10-27T10:44:14.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iueu_gjcOuqZhv0_" /><figcaption>Photo by <a href="https://unsplash.com/@uxstore?utm_source=medium&amp;utm_medium=referral">UX Store</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I have to admit: I don’t always have time to keep up with all the new CSS technologies, and I don’t always know which ones are worth my time.</p><p>To organize my thoughts, I produced an overview of all the major CSS technologies that are gaining popularity today and might still be relevant tomorrow: CSS-in-JS, Component-Oriented CSS*, and Utility First CSS.</p><p>I wrote about the big ideas behind them and the consequences of these ideas for code architecture, performance, and dev velocity.</p><p>You can try all the code examples via Wix Components Studio by clicking <a href="https://vlad-karnauch.github.io/the-future-of-css/">here</a>.</p><p>*Component Oriented CSS: A term I coined, it refers to CSS frameworks, mostly preprocessors, that scope CSS locally, such as Stylable, or CSS Modules.</p><h3>Vanilla CSS</h3><p>CSS<strong> (C</strong>ascading <strong>S</strong>tyle <strong>S</strong>heets) was initially released in 1996 during the Browser wars: Microsofts Internet Explorer and Netscape Navigator each tried to define the web, which, at the time, was mostly static pages that displayed data.</p><p>One of the great advantages of CSS was the way styles “cascaded” from a parent to affect all of its children. This worked very well for the relatively small projects that existed in 1996 because it reduced duplication, made CSS easy to understand, and the inheritance easy to trace.</p><p>However, as projects grow in complexity, cascading becomes a liability; CSS rules often depend on the HTML structure, so every change in either requires changes in both. In addition, a small change in any rule can have unintended consequences on other pages due to global scope.</p><p>Using preprocessors like <a href="https://sass-lang.com/">SASS</a> or <a href="https://lesscss.org/">less</a> and naming conventions like <a href="http://getbem.com/introduction/">BEM</a> can help organize a team’s code, but modern technologies can achieve better results with relative ease.</p><h3>CSS in JS</h3><h4><a href="https://styled-components.com/">Styled Components</a></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3194da0d80ebe51f317ba36ad1985454/href">https://medium.com/media/3194da0d80ebe51f317ba36ad1985454/href</a></iframe><p>Styled Components is a package that is installed using the package manager.</p><p>Button component is created by providing the HTML tag (button), and the style is provided as a string using a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates">tagged template string</a>. Inside, Styled-Components creates a unique className for the new Button Component and adds the className to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model">CSSOM</a>*</p><p>Finally, styled.button returns a new component that uses the newly created style so that it can be used.</p><p><a href="https://vlad-karnauch.github.io/the-future-of-css/?simulation=%2Fsrc%2F_wcs%2Fboards%2Fstyled-components-button%2Fstyled-components.board.tsx&amp;type=board">Try it out with Wix Component Studio</a></p><p>*CSSOM (CSS Object Model) is like the DOM, but for CSS, it allows adding CSS at runtime.</p><h4><a href="https://emotion.sh/docs/introduction">Emotion</a></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b36b7d174e8732a9bc7db790f9238613/href">https://medium.com/media/b36b7d174e8732a9bc7db790f9238613/href</a></iframe><p>Emotion is also a package that can be installed using the package manager. It works similarly to Styled-Components: the CSS prop is replaced with a uniquely generated className, and the style is added to the CSSOM.</p><p>By now, most libraries that allow CSS-in-js support both syntaxes.</p><p>The tagged-template-string format is useful because we can directly load read legacy CSS from files, but it doesn’t support any syntax highlighting and code completion supported by the CSS prop out of the box.</p><p><a href="https://vlad-karnauch.github.io/the-future-of-css/?simulation=%2Fsrc%2F_wcs%2Fboards%2Femotion-button%2Femotion.board.tsx&amp;type=board">Try it out with Wix Component Studio</a>.</p><h4><strong><em>CSS-in-JS Advantages</em></strong></h4><ul><li>Local scoping, since a unique className is generated for each component, the styling is now scoped to the component, and styles will no longer override each other simply because they are no longer global. In other words: these components can be extended but not modified from the outside.</li><li>Global scoping (cascading) was essential for CSS to avoid code duplication, instead sharing is easy because this is javascript code</li><li>The main building block of our app is now the component. This no longer feels like regular CSS. Instead, it becomes functional programming: the styling of a component is now an integral part of it, and they are both encapsulated into a single unit that exposes an API that can be reused.</li><li>This is javascript code, making it much easier to apply complex logic to your style rules, create dynamic interfaces, and reuse code.</li></ul><h4>CSS-in-JS Disadvantages</h4><ul><li>Loss of separation of concerns, CSS was designed so that content would be separated from presentation, with CSS-in-js component logic, animations, themes, and layouts all mixed together in the component; when not carefully managed, this could lead to unmaintainable code.</li><li>Browsers can render regular CSS much faster than styling that requires code to run; this can be alleviated by separating the critical CSS that is needed to load the user’s initial viewport and with server-side rendering.</li><li>An Extra layer of complexity needs to be set up and maintained and requires a steeper learning curve than vanilla CSS. This is well worth it for teams working on relatively large projects but can be detrimental in smaller ones.</li></ul><h3>Component Oriented CSS</h3><blockquote>keep everything we liked about CSS, and build upon the good work that the styles-in-JS community was producing. So, while we’re bullish about our approach and firmly defend the virtues of CSS, we owe a debt of gratitude to those folks pushing the boundaries in the other direction. Thanks, friends! 👬👫👭 — css modules team</blockquote><h4><a href="https://github.com/css-modules/css-modules">CSS Modules</a></h4><p>CSS Modules is a pre-processing step: by default, styles are scoped locally to the current component, and the transpiler ensures no conflicts.</p><p>Let’s see how it works. First, we add a button.css, just like good old CSS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36b5e409b24e065cc8b74f3de6224f4f/href">https://medium.com/media/36b5e409b24e065cc8b74f3de6224f4f/href</a></iframe><p>Next, we import styles from the CSS we just created and apply classNames from it to our JSX:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fd4cb8a4db83b732443af26524c8dfb/href">https://medium.com/media/0fd4cb8a4db83b732443af26524c8dfb/href</a></iframe><p>The transpiler will make these styles locally scoped, and the result looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d851b2bef73ab598dc64ac78378243a/href">https://medium.com/media/6d851b2bef73ab598dc64ac78378243a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c50ef0b52ee08a1b9502561ac5c90fe8/href">https://medium.com/media/c50ef0b52ee08a1b9502561ac5c90fe8/href</a></iframe><h4>Avoiding Code Duplication</h4><p>By scoping locally, we sidestep the global scope issue but lose some of the advantages gained by cascading. Instead, to avoid code duplication, we use the composes keyword:<br>Let’s say we want a cancel button that is the same but with a different text color:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4792d9df9d1a3e7dc23bc082822ed88/href">https://medium.com/media/f4792d9df9d1a3e7dc23bc082822ed88/href</a></iframe><p>Then, using import styles from ‘./button.css’; will produce something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da4faa209465ced46c9b687b52157fe6/href">https://medium.com/media/da4faa209465ced46c9b687b52157fe6/href</a></iframe><p>CSS modules adds both classNames to a component.</p><h4><a href="https://stylable.io/">Stylable</a></h4><p>CSS Modules helps manage large CSS projects by adding namespaces. Stylable is a CSS preprocessor that takes it even further by adding a type system.<br>Stylable exposes an API that can be styled, meaning selector issues are visible in build time rather than run time. For example, you’ll see it in the IDE if a button no longer supports an icon. Every developer knows that detecting and fixing a bug costs exponentially more during acceptance testing than during coding.<br>Stylable files look very similar to CSS files, but they are scoped:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a6a4892791f083ab2c2e2afd8076148/href">https://medium.com/media/8a6a4892791f083ab2c2e2afd8076148/href</a></iframe><p>In addition, because we now have an elaborate type system, we can now extend this button from parent components; for example this could be a dialog containing our button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d421bf0eaf1be377987737aef28a468f/href">https://medium.com/media/d421bf0eaf1be377987737aef28a468f/href</a></iframe><p><a href="https://vlad-karnauch.github.io/the-future-of-css/?simulation=%2Fsrc%2F_wcs%2Fboards%2Fstylable-dialog%2Fstylable-dialog.board.tsx&amp;type=board">Try it out with Wix Component Studio</a></p><h4>Component Oriented CSS Advantages</h4><ul><li>We can “compose” some of the CSS-in-js advantages here: local scoping, composition and the main building block of our project is still the component. That’s why I called it “component oriented.”</li><li>Concerns are separated, just like with CSS: themes and layouts are, by default, separated from the component without the need to carefully manage them.</li><li>Runtime performance is not affected, unlike CSS-in-JS, which executes in runtime and potentially slows down your app; this is a preprocessing step, resulting in plain CSS, which the browser is already heavily optimized for rendering.</li></ul><h4>Component Oriented CSS Disadvantages</h4><ul><li>No longer dynamic, complex logic is more challenging to implement; some styling features can’t be implemented without JS.</li><li>An extra layer of complexity, though with a gentler learning curve than what CSS-in-JS offers.</li></ul><h3>Utility-First CSS</h3><p>The idea is to have reusable, tiny classes like flex,pt-4, text-center, androtate-90 that can be composed and used in any component.</p><p>Consequentially, around 90%-95% of most projects’ CSS can be translated into these atoms. For example, the following component has the following HTML code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PbNg5H_V8h3Sm6PJAre8Q.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b950c1c5f6c718492c70f1c5715f18a/href">https://medium.com/media/1b950c1c5f6c718492c70f1c5715f18a/href</a></iframe><h4>Utility-First CSS Advantages</h4><ul><li>HTML is now dependent on CSS; it has to know that certain CSS classes exist and how to combine them properly, making the CSS completely independent of the HTML and allowing programmers to quickly iterate on the design system regardless of the content. Smooth Iterations mean fast improvements and sleek products; that’s why Utility-First CSS results in some of the best component libraries. Check out <a href="https://tailwindcss.com/">Tailwind</a>, and <a href="https://getbootstrap.com/">Bootstrap</a></li><li>The design system is more consistent, border-dark-soft, will always have the same color and width, and can be easily changed in all places. However, this can easily be achieved with composition and variables.</li><li>CSS files are much smaller. CSS usually grows linearly with project size: more components mean more classes and larger files, while utility-first CSS grows logarithmically with project size: border-dark-soft is defined once and used many times</li></ul><h4>Utility-First CSS Disadvantages</h4><ul><li>CSS was designed to be independent of HTML, that’s why we name classes based on content: button, author-bio, etc., or in other words, CSS is dependent on HTML and needs to know what classes were exposed. At the end of the day, the more volatile parts of our software that change the most should depend on the ones that change the least: in most projects, users like features and functionality (e.g., components) to be continually added, but they like the design-system to stay the same.</li><li>The naming convention requires a learning curve: what is py-2? We end up with these long unreadable classes: “py-2 px-4 border-r border-dark-soft”, that are hard to learn and difficult to understand</li><li>Adds another layer of complexity to our stack, requiring setting up the naming conventions and adding a post-CSS processor to minify the result</li></ul><h3>At the end of the day…</h3><p>CSS has a fascinating future ahead of it. These technologies are here to stay, grow, and become easier to use. However, teams must be careful when selecting a specific technology over others. In general:</p><ul><li>CSS-in-JS is worth the performance hit when complex logic is associated with styling.</li><li>Component Oriented CSS is perfect for organizing large projects, with many independent components.</li><li>Utility-First CSS seems to produce the best-looking interfaces, this makes a lot of sense: if the CSS is independent, it can be iterated upon frequently.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1764e9766875" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wix-engineering/the-future-of-css-1764e9766875">The Future of CSS</a> was originally published in <a href="https://medium.com/wix-engineering">Wix Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>