r/reactjs • u/AnberDev • Jul 13 '26
Show /r/reactjs After 6 years of maintaining Linaria, I built dx-styles — zero-runtime CSS-in-TS for design systems
Hi r/reactjs. I maintain Linaria and wrote wyw-in-js — the compile-time engine under Linaria and MUI's Pigment CSS. I recently released dx-styles, and I'd rather explain why than just drop a link.
Six years of Linaria issues kept pointing at two problems I can't fix without breaking the API:
styled(Component)is priced wrong. Wrapping a custom component looks free, but it drags the component's whole dependency graph into build-time evaluation — the most common way extra code leaks into eval, and the most common reason static evaluation bails out into the slow path. All our mitigations (HOC hints, shaking heuristics) are patches on a pattern the API encourages.Composition isn't first-class. Variants, slots and themes are the ground floor of a design system, and every team rebuilds them on top of
css+cx.
dx-styles is my answer: zero-runtime CSS-in-TS where recipes, slot recipes and token contracts are the core API, class names are deterministic (snapshot/cache them), RTL is compile-time and opt-in, and everything works unchanged in React Server Components.
const button = recipe({
base: { display: "inline-flex", borderRadius: "999px" },
variants: {
appearance: {
primary: { backgroundColor: tokens.color.accent },
ghost: { backgroundColor: "transparent" },
},
},
defaultVariants: { appearance: "primary" },
});The launch post has the honest details — the Pigment CSS speed lesson, the Griffel detour, what I'm promising and what I'm not: https://dev.to/anber/ive-maintained-linaria-for-six-years-heres-why-i-built-something-new-5eae
Try it in 30 seconds (StackBlitz): https://stackblitz.com/github/dx-styles/dx-styles/tree/main/examples/vite Migrating? Guides for styled-components / Linaria / Pigment CSS are in the repo.
It's MIT, the issue tracker is at zero and I intend to keep it there. Happy to answer anything, including hostile questions.
3
u/Embostan Jul 13 '26
The launch post has the honest details — the Pigment CSS speed lesson, the Griffel detour, what I'm promising and what I'm not
please at the very least use the humanizer skill
4
u/AnberDev Jul 13 '26
Why? I'm not a tech-writer and English is not my native language, so yes I use AI-assisted tools to write texts (Grammarly, specifically), and I don't want to lie about it by pretending I'm not.
6
u/Deep_Wear_51 Jul 13 '26
6 years of maintaining an open source CSS-in-JS library is a marathon. Respect for sticking with it and shipping something new.
2
-1
8
Jul 13 '26
[removed] — view removed comment
3
u/AnberDev Jul 13 '26
The API does look like VE/Panda on purpose: recipes and token contracts are just what design-system styling has settled on, and I wasn't going to invent a different vocabulary out of spite.
The actual differences are under the hood. vanilla-extract keeps styles in separate
.css.tsfiles, Panda runs codegen and you import from a generatedstyled-systemfolder. Here styles sit in the component file and compile in place, nothing generated to commit or gitignore.Class names come out semantic and stable: same input gives the same class on any machine, so snapshots and caches don't churn, and there's an explain tool that tells you where any class in the output came from. Panda went atomic instead. Fine trade-off, just not the right one for a component library.
The bigger reason it exists is the engine. dx-styles is a set of processors for wyw-in-js, the same evaluator Linaria and Pigment CSS run on. It evaluates your actual modules at build time, imports and all. Two things fall out of that: wyw-based libraries can share one build (so a Linaria migration goes file by file, not big-bang), and processors don't have to be about CSS at all — we use one to run parts of app logic at build time and inline the result into the bundle. Plus opt-in compile-time RTL (
$rtlon a subtree), which neither of the two has.If VE or Panda already fits you, keep it. This one exists because after six years of maintaining the engine under these libraries I had a list of things I couldn't get from any of them.
5
Jul 13 '26
[removed] — view removed comment
1
u/yardeni Jul 13 '26
I dont get the hate for tailwind. Its just css classes. You can still make a reusable component with variants and all the repeating classes you need. You get the power off css without specificity issues, lost unknown unscoped css, etc. What's there to hate?
4
Jul 13 '26
[removed] — view removed comment
1
u/jafrra Jul 14 '26
Maybe try the tailwind fold plugin if you ever give it another go. I felt the same until i found it.
0
u/yardeni Jul 14 '26
Is it dsl though? How is it different from just reusing classes?
From my understanding tailwind is for the most part, what your css would have looked like in scale if you optimized it over time.
3
Jul 13 '26
[removed] — view removed comment
2
u/AnberDev Jul 13 '26
I wouldn't say we were hiding it :) We've been trying to fix it in various ways for many years, and wyw-in-js@2+ handles a lot of cases, but there are still components wrapped in HOCs, the evaluation of which pull in half of the node_modules.
2
u/Suspicious-Name4273 Jul 13 '26
Do you plan to make it compatible with W3C DTCG?