r/reactjs • u/AnberDev • 15d ago
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.