You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As there is no discussion tab in this repo, I think an issue would be appropriate.
Goober may be very small, having CSS in JS in 1kb gzipped is amazing, but it may not be good to use in big projects. In andreipfeiffer's CSS in JS Goober Analysis he mentions how inefficient Goober can be for dynamic styles.
Not only that but Goober does not allow Atomic CSS, when an update is made to the stylesheet, not only it seems to duplicate, but it seems to duplicate the whole rule, even for things that haven't been changed at all. Here is a CodeSandbox sample that demonstrates this behaviour.
The 1kb promise may look good to the eyes, but I think that behind there's a very unoptimized library that in the end, suffers from being optimized as it is only 1kb.
How easy would it be to replace Goober in the internals of Solid-Styled-Components?
Has anyone built something in production with SSC that's scalable?
There's some examples that I can give of alternatives to CSS in JS but I would like to first hear your opinion about it.
Yeah great discussion topic. I did pick Goober on size, and not much else. I'm not so much a CSS in JS person and I was just trying to check the boxes. Definitely interested to hear thoughts.
Streamich, the creator of React-Use (useCss) also the creator of FreeStyler may have created but mentioned CSS in JS Generations, I really like his approach to the situation but I would like to add more to it.
I imagine that Solid Styled Components was made to look like React Styled Components, mommy said never judge a book by its cover but I'm doing it now.
I was going to do some benchmarking because it is of my interest to really know which CSS in JS Libraries is the best, but just noticed how incorrect the results would turn out.
To help a little to the research I've made a list of CSS in JS Libraries (From most star count to less star count), here's the list:
There's a lot of differences also in the way the CSS is implemented in the page, some use CSSOM, some use single style tag injections while others use multiple style tag injections (better for 5th gens while worse for 3rd gens). CSS in JS is a whole world where everyone's trying to grab a little of performance in something.
The way I do it in my personal projects are to use nano-css or any 5th generation performant library and implement my own theme system on top of it, using styled-system Styled Props, I love them.
Reacted by 0x241F31, Miłosz, Riccardo, Philippe, Asher Chen (YLC), ryoppippi, kii, Nunawa, David Ferreira, Nevroz Arslan and 2 more
Reacted by danil-instacart, Tom Byrer, Yuji Sugiura, Oyama Michinoku and Kavian
@phiberber I ran into this amazing thread when realized that goober is not well suited for the CSP policy default-src 'self' | style-src 'self' since it injects inline <style> at runtime, and there are no rollup/vite plugins for making it generate actual *.css files at build time, the way https://www.npmjs.com/package/mini-css-extract-plugin does it with webpack (not sure if mini-css-extract-plugin would ever work with goober).
I'm far from understanding the whole landscape of CSS-in-JS, but so far, linaria looks like the best of all worlds: it's among the most popular ones, lightweight, it correctly extracts *.css and has the most conventional developer experience with component co-location (pretty similar to hugely popular styled-components, emotion, etc.) I briefly looked at what is the so-called 5th generation and, honestly, not sold by it so far – probably DX looks too unusual.
There's a problem with zero runtime css-in-js that's it has no runtime at all. Dynamic styling is pretty limited because of that, I would recommend Solid-styled-components to look like and act like styled-components, which has a runtime and allows any kind of dynamic prop.
That's why all the recommendations I've made are libraries with runtime. This project probably only exists to extend the Solid ecosystem, that has no problem at all, the problem is making an unpredictable library.
Don't get me wrong, Linaria is really good, but it's not a perfect replacement for styled-components nor goober.
One thing that I had never seen before was an adapter css-in-js system, where one could use the same API with different libraries, just like deploy adapters, if that were the case, I would agree in supporting Linaria.
About the CSS files, it's a big problem that static CSS is generated in runtime when SSRing. I'vent noticed any library yet that allows static css extraction while still running with runtime dynamic styles. Nano-css does have a really good implementation of static vs dynamic styles, but I don't think that would be enough to work with.
It has always been a thought of mine of creating such library, which through partial evaluation is able to determine dynamic styles, in-line static styles and extract them to pure css at build time, while then only delivering the JS of the dynamic styles. I've tried to do that once, but the babel's partial evaluation system had some big problems.
I would be up to help creating such library, but I don't think that's what @ryansolid is planning to this SSC. That's why I still keep my recommendations.
I would also like to add, Solid Start is implementing the Islands Architecture. In my opinion not only Islands are something hard to achieve with a good level of DX by it own, but implementing CSS-in-JS using Islands always turned out to be a mess (to me).
I don't think this project is a serious project. I know it's here to be used, but it has been shown that Ryan is not focusing on SSC. I think SSC exists only because Solid needs ecosystem, Ryan is then trying to deliver that fast, at the cost of using making bad decisions (goober).
If this project were to be serious, I would suggest discussing about the following topics:
Should SSC be exactly like Styled Components.
Should SSC do Static CSS extraction?
Should SSC do Dynamic CSS isolation?
How would theme properties work inside Islands?
How would component loading work inside Islands? Do we need to load the full component?
Should SSC have a runtime? Should it be a compiler?
Should SSC focus on microbenchmarks? If so, from who? How valid can these microbenchmarks be?
Should SSC be a serious project, in case it isn't yet?
It's a lot of discussion and it's all related subjects. Should this be all discussed here in this thread? The islands problem does have a big effect in which library to replace Goober with, being like Styled Components too. I'm really unsure about the future of this issue, it can go to amazing places, it can turn into a mess.
It is also good to mention. Solid Styled Components is currently being used along Styled-System by some people. There's even an issue about it solidjs/solid#148.
When thinking of a goober alternative, it would be good to check for the compatibility of that x library with Styled-System.
I'd also like to know about @ryansolid's opinion on this, it may be too late to change libraries, I'm not in the position to say that though.
The only advantage of goober is it size. Class generation is wrong, it not respecting nesting of class and their relations. This is related to recently opened issues: solidjs/solid-styled-components#7, cristianbote/goober#397
There is very very simple example, where this library totaly fails. It was very hard to debug and to find this. I have spent a lot of time to find the issue in my components styling. And there was no issues, styling was perfect, but goober thinks different and broke everithing.
Before you try this example, try to guess the style of all 4 components, on parent element hover.
There's a problem with zero runtime css-in-js that's it has no runtime at all. Dynamic styling is pretty limited because of that, I would recommend Solid-styled-components to look like and act like styled-components, which has a runtime and allows any kind of dynamic prop.
When thinking of a goober alternative, it would be good to check for the compatibility of that x library with Styled-System.
I think the best option is Linaria or any Zero-runtime library for css-in-js, in fact there is a PR for solid integration in Linaria repo
Like I've said and has been quoted. Solid-Styled-Components should in my strong opinion look and act like Styled-Components.
I would recommend a Solid-Styled library to be created to support multiple CSS in JS adapters, which is the idea I've already mentioned here. Then Linaria would really be a good option as an adapter.
I agree that the only good factor of Goober is its size.
@ryansolid Can this issue have your attention? It makes no sense using Solid which is one of the fastest frameworks along with Solid-Styled-Components currently. SSC uses Goober which has been shown to have serious performance issues when updating styles (Like changing from Light theme to Dark theme).
Reacted by Asher Chen (YLC), Patrik Smělý, RainArroDev, Ivan Čurić and Robin Millette
const$color=createState("red");const$fontSize=createState("16px");// In your component:<div><style>{css`.btn{color:${$color};font-size:${$fontSize};} `}</style><buttonclass="btn">Click me</button></div>
the css helper would parse the template string and find signal references, generate a stable identifier for each signal (e.g. --signal-123) and then replace signal references with the custom property references.
the parent div would set up subscriptions to update just those specific custom properties on the parent element.
this way, you can update individual custom properties on the element, and a single global stylesheet stays in place.
okay, so this is limited to "things you can do with custom properties", e.g. no conditional CSS - if you wanted that, you'd have to set it up by rendering/removing individual <style> tags, or using the upcoming native CSS conditionals, etc.
but it's potentially a lot simpler and cleaner than parsing and regenerating actual CSS... maybe? 😊
I've been refining this idea, here's where I'm at now:
const[color,setColor]=createSignal("red");const[fontSize,setFontSize]=createSignal("16px");// Define the style with explicit signal parameters and proper selectorsconstButton=createStyle({$color: color,$fontSize: fontSize,})` .btn { color: ${color}; font-size: ${fontSize}; }`// UsagefunctionApp(){return(<Buttonas="button"class="btn"action="/login"$color="red"$fontSize="24px">Clickme</Button>);}
the object maps property names to signals, providing type safety with inference.
the stylesheet is literal CSS that gets injected at the time of creation - it never updates, so it's easy to extract.
interpolated signals in the CSS string gets replaced with custom properties like --solid-123 etc.
the rendered element get a style attribute injecting the custom properties directly. (probably useful for debugging.)
for some use cases (like this button) you'd likely want the element type and class attribute specified by default, so:
constButton=createStyle({$color: color,$fontSize: fontSize,})` .btn { color: ${color}; font-size: ${fontSize}; }`.button({type: 'button',className: 'btn'});// 👈 element type and default props// UsagefunctionApp(){return(<Buttonaction="/login"$color="red"$fontSize="24px">Click me</Button>);}
the component returned by the CSS factory function is also a proxy that can generate a component with the as attribute and other props populated with default values.
this would work for structured elements like lists as well, and could probably support constant and prop interpolations too:
again, in this example, the p is a proxy that generates e.g. --solid-123 placeholders.
the syntax is a bit like styled components, but it is much simpler, since it doesn't really modify the CSS at all.
if you don't like making up class names, maybe we could have it do a simple search-and-replace for :root or :scope maybe? and of course, any CSS features you choose, like nested selectors could be used too:
constList=createStyle()` :scope { background: ${bgColor}; li { color: ${p=>p.$itemColor}; padding: 8px; } }`.ul();// 👈 class defaults to a generated :scope placeholder
with nested selectors and structures, because it's using custom properties, maybe we could override in nested elements as well - in the example above, there's no reason you couldn't override $itemColor for the individual list items. I'm not sure what the most practical syntax would be for that though.
of course, as mentioned, this approach is limited compared to styled-components, since you can only do what CSS can do.
I don't know that that's a bad thing though? it certainly eases the learning curve, and likely makes for a very lightweight and efficient implementation.
I'd love to hear your thoughts? :-)
Linaria looks cool as well, if you want to support something existing rather than reinventing the wheel. Personally, I'm questing for something simple, something that stays close to the platform, and provides a single pattern that works well for everything. I'm sure there's still tons of stuff I haven't thought of, so feel free to shoot this full of holes. 😅
for your understanding, this approach stops short of building your components for you - it can build the styles and an element, and help you set custom properties, but it's not styled components... you'd still want a proper component wrapping your styles providing higher degrees of abstraction, for example:
// The styling utility - internal (not exported) and focused purely on stylesconstCardStyle=createStyle()` :scope { border: 1px solid ${p=>p.$borderColor}; border-radius: ${p=>p.$radius}; background: ${p=>p.$bg}; } :scope .header { background: ${p=>p.$headerBg}; padding: 12px; } :scope .content { padding: ${p=>p.$contentPadding}; }`.div();// A proper component that uses the styles and provides a semantic API:exportfunctionCard({ size ="medium", theme ="default", title, children }){// Map abstract props to specific styling values ("CSS in JS")constthemeColors={default: {border: "#ddd",bg: "white",header: "#f5f5f5"},blue: {border: "#0074d9",bg: "#f0f8ff",header: "#0074d9"}};constsizeMappings={small: {radius: "4px",padding: "12px"},medium: {radius: "8px",padding: "16px"},large: {radius: "12px",padding: "24px"}};constcolors=themeColors[theme];constdimensions=sizeMappings[size];return(<CardStyle$borderColor={colors.border}$bg={colors.bg}$headerBg={colors.header}$radius={dimensions.radius}$contentPadding={dimensions.padding}>{title&&<divclassName="header">{title}</div>}<divclassName="content">{children}</div></CardStyle>);}// Usage - clean, semantic APIfunctionApp(){return(<Cardsize="large"theme="blue"title="My Card">
Card content goes here
</Card>);}
okay, I'm going to stop spamming this thread, but idk... I could see myself using this maybe?! 😄
this appears to explore the direction I was presenting above, and it's quite interesting - it's based on the author's own implementation of signals, so the patterns he's come up with are all centered around signals and reactivity, along with the idea that I was peddling above, of essentially coupling signals to custom properties. I quite like the direction he's taking with this, and in all my research on this topic, I haven't seen another library doing this. It's worth a look, I think.
this is based on CSS modules, and honestly, my own personal opinion on CSS modules runs hot and cold, but... this is interesting, because it takes a completely different direction, one of mainly leaving the CSS out of the equation and delegating that to CSS modules, and as such, you could argue it's not really CSS-in-JS, per se. instead, this library focuses on CSS integration at the component level, with abstractions around "variants" and styling of intrinsic elements, etc.
honestly, I've spent almost 3 days straight deep diving on all the various CSS approaches, and I'm honestly not sure what to think - every CSS-in-JS solution seems to have drawbacks or limitations. I think, no matter what you pick, you're going to miss something offered by another solution. I don't think there's an "one size fits all" here - CSS is complex, and UI libraries are complex, and I think, essentially, none of these pieces are to fit together exactly.
personally, I'd very much like to see something that stays reasonably close to the platform, or at least, close to technologies that are reasonably common across the ecosystem. think @ryanmorr/fusion but maybe without the CSS preprocessing maybe?
CSS-in-JS offers a great opportunity to change styles based on component props in realtime. That was a killer feature, at least for me. But they had a lot of drawbacks:
Performance
The first render takes longer - the bigger the project, the longer you wait page to render. Even on small pages you can feel this.
Developer must take care about how frequenty props are changing, this can make significant impact on persformance.
CSS Cascade
Some libraries are better at this than others. But you will face it on any project harder then "todo list".
Server side rendering
Modern CSS now provides enough support for features like custom properties and :has() selector. Using them, there is no need to use css-in-js.
Modern CSS now provides enough support for features like custom properties and :has() selector. Using them, there is no need to use css-in-js.
@Profesor08 what do you use? just plain CSS files? any particular pattern? (BEM? utility-first?)
I would always default to plain CSS for simple web sites - but in an application context, one of the main problems with plain CSS is just simply that of coming up with class names. It becomes quite a meaningless exercise - at least with something like BEM, where you have to name every individual element within a component structure. It's a waste of time, and often really unhelpful to the next person reading the code.
It also gets problematic over time - for example, needing to refactor (again, at least with something like BEM) because your element structure needs to change, it often turns out the CSS is extremely fragile. You can counter some of this with utility classes for styles with structural dependencies (mostly layouts) but you're still stuck with a lot of noisy, unhelpful names, clunky and error prone refactoring efforts, and so on. And all of this compounds when working on a team.
I think custom properties, the :has selector, or even things like cascade layers (which make CSS massively more scalable) do not address any of these issues.
In a component oriented context (e.g. with most UI frameworks) the components drive the markup structure, so it probably just makes sense to let them control the styling as well, I think. These concerns are naturally highly coupled - there is no real "separation of concerns" you can achieve here, what you get instead is just "fragmentation of concerns".
Almost no matter how you're doing CSS, if you have components, the CSS ends up mirroring the structure of the components. The cascading part of CSS was just more relevant in a time before components, I think.
At least that's my experience, which is why I'm interested in finding a good approach to CSS-in-JS.
@mindplay-dk I switched to CSS Modules. I did some work to configure them in my projects and ensure they bundled correctly. So now, I don't care about dead code, about naming, about relations. If I need to modify some component in scope of another component, I can just pass an additional class name, and this will not break nothing in other places. If I need to modify the component itself, I can do this at any time, and then to check where it is used and easily find where it is broken. Because now is everithing is under control.
@phiberber, hi! You seem to be extremely knowledgeable in CSS frameworks and furthermore our views seem to align, so I would appreciate your opinion.
What styling solution would you recommend as of 2025 for a mid-scope (4-6 months) project in SolidJS and TypeScript?
I'd prefer a styling solution, where:
Style is a function of state
Minimum boilerplate, by "state" above I preferably mean just all the variables in the scope, without constructing an intermediate "state" object
Utilizing the existing power/abstractions of JavaScript (functions, conditions, etc.) instead of a separate custom language
I imagine being able to write something like this:
I see. Rendering speed is my secondary concern, because the app (esoteric coding game) won't be very big. My biggest concern is developer speed/experience, so I can get the project over the finish line.
So being less dynamic also has a benefit.
Yes, totally. At the moment my design is very ad-hoc, trying to get the basic layout of things right, but as a non-mega-experienced designer I see how having some limited options may lead to better consistency and better app.
And LLMs are also probably better at Tailwind compared to lesser known solutions.
At work, we switched from styled-components to Emotion.
@emotion/css is just basic, co-located CSS with JS interpolations, and it's really quite nice - just that would have been fine for me.
We also use @emotion/react and @emotion/styled, and @emotion/eslint-plugin to enforce some conventions.
This a very large React project with tons of screens with custom CSS - Emotion is noticeably faster than styled-components, so that alone made it worth the switch.
If you're concerned about runtime micro performance or bundle size, in my opinion, you're worrying about all the wrong things. Unless you're building a real-time app (games etc.) of some sort, it won't matter - performance of Emotion is just fine, your users will never notice a difference. What will matter is ease of reading, understanding and maintaining the code - @emotion/css is literally just inline CSS, so this is not a big decision or any real learning curve, at least not for apps. (for web sites, you might want to think about using something that compiles to CSS - but this is actually a drawback if you're working on an app, because the run-time evaluation in frameworks like Emotion lets you preview changes instantly.)
Tailwind just moves complexity from CSS into your markup, which is already burdened with JSX templating/logic - it's too unstructured, mixing too many things into your markup, and it's just too far off from CSS. Set yourself up with design tokens or CSS vars for scales and colors etc. instead. - create a few global utility classes (or yes, borrow them from Tailwind!) for things like flex/grid layout; things that have structural dependencies and therefore actually benefit from being grounded in the markup. Colors, text-styles, borders, shadows, spacing, etc. have no structural dependencies - utilities don't solve any problem for those, and you're much better off seeing play-button or shopping-cart than a list of 25 meaningless class-names that don't tell you what you're looking at. Just my two cents. 😊
As for Solid, I still don't know... fusion is definitely a very cool idea - if we could have something like this that actually leverages signals, that would seem like a very Solid approach. all-in on signals! But I'm guessing you want things like server-side rendering, so I don't know if this type of approach could easily or naturally accommodate that. Probably not. Linaria does something of that sort for React, I guess - but it's definitely not simple... 🤔
@mindplay-dk thanks for sharing your experience. I'll look into Emotion and fusion.
I am making a game, but not real-time game: esoteric coding game, think like something like SolidJS interactive tutorial, but you also have a list of automatic tests for each task. As I mentioned before, rendering speed is indeed not my concern. I would like to get-rid of "jump cuts" which are prevalent across 99.9% of websites (ideally, nothing on the screen should ever pop in/out of existence without transition), but it's likely to end up being out-of-scope.
I expect the project to take 4-6 months and it being my first solo-dev game without any external pressure, the biggest concern is just to stick with it, get things done and finish it. So:
What will matter is ease of reading, understanding and maintaining the code
(+developer speed) is absolutely true for me.
But I'm guessing you want things like server-side rendering
I imagine I might have the ability to share solutions and it would be nice if such pages where indexed by Google, but it's not mission-critical. So far I already had to temporarily disable SSR in Solid Start template for some small reason I don't remember.
Activity
ryansolid commentedon Oct 17, 2022
Yeah great discussion topic. I did pick Goober on size, and not much else. I'm not so much a CSS in JS person and I was just trying to check the boxes. Definitely interested to hear thoughts.
phiberber commentedon Oct 17, 2022
Streamich, the creator of React-Use (useCss) also the creator of FreeStyler may have created but mentioned CSS in JS Generations, I really like his approach to the situation but I would like to add more to it.
I imagine that Solid Styled Components was made to look like React Styled Components, mommy said never judge a book by its cover but I'm doing it now.
I was going to do some benchmarking because it is of my interest to really know which CSS in JS Libraries is the best, but just noticed how incorrect the results would turn out.
To help a little to the research I've made a list of CSS in JS Libraries (From most star count to less star count), here's the list:
Styled Components (37.6k Stars) - 4th Generation
Emotion (15.6k Stars) - 4th Generation
Linaria (9.7k Stars) - 4th Generation
Radium (Archived) (7.4k Stars) - 2nd Generation
Styled-JSX (7.2k Stars) - 3rd Generation
JSS (6.8k Stars) - 3rd Generation
Stitches (6.4k Stars) - 5th Generation
Vanilla Extract (6.4k Stars) - 3rd Generation (Maybe 5th Generation)
Aphrodite (5.3k Stars) - 3rd Generation
Glamorous (3.7k Stars) - 4th Generation
Glamor (3.6k Stars) - 3rd Generation
Styletron (3.3k Stars) - 3rd Generation
TypeStyle (3k Stars) - 3rd Generation
Goober (2.7k Stars) - 5th Generation
Fela (2.2k Stars) - 5th Generation
Astroturf (2.1k Stars) - 3rd Generation
Xstyled (2.1k Stars) - 4th Generation
Compiled (1.7k Stars) - 5th Generation
Cxs (1.2k Stars) - 5th Generation
Treat (1.1k Stars) - 3rd Generation
Griffel (824 Stars) - 3rd Generation
Otion (620 Stars) - 4th maybe 5th Generation
CsJS (578 Stars) - 3rd Generation
NyanCss (555 Stars) - 1st Generation
Glam (502 Stars) - 5th Generation
Fower (485 Stars) - 5th Generation
Style9 (447 Stars) - 3rd Generation
NanoCss (403 Stars) - 5th Generation
Picostyle (350 Stars) - 4th Generation
Trousers (300 Stars) - 5th Generation
Css-Zero (283 Stars) - 3rd Generation
FreeStyler (265 Stars) - 5th Generation
Styled-JSS (220 Stars) - 4th Generation
Aesthetic (199 Stars) - 4th Generation
Stylex (184 Stars) - 3rd Generation
Filbert (168 Stars) - 4th Generation
J2c (167 Stars) - 3rd Generation
Style-it (152 Stars) - 5th Generation
Scoped-Style (135 Stars) - 4th Generation
Uranium (127 Stars) - 2nd Generation
Macaron (119 Stars) - 3rd Generation (Maybe 5th Generation)
NanoStyled (103 Stars) - 4th Generation
Rockey (97 Stars) - 4th Generation
Css-Out-Js (90 Stars) - 3rd Generation
Catom (86 Stars) - 3rd Generation
Nano-Style (85 Stars) - 4th Generation
Yocss (60 Stars) - 5th Generation
HyperStyles (59 Stars) - 1st Generation
Stylemug (54 Stars) - 3rd Generation
Tsstyled (52 Stars) - 4th Generation
Glitz (43 Stars) - 5th Generation
SuperStyle (Archived) (39 Stars) - 4th Generation
Dash-UI (30 Stars) - 3rd Generation
Taddy (26 Stars) - 3rd Generation
Classy (24 Stars) - 4th Generation
Cease (21 Stars) - 4th Generation
Glory (20 Stars) - 5th Generation
Tasty (19 Stars) - 3rd Generation
Tassel (18 Stars) - 3rd Generation
Sheety (17 Stars) - 3rd Generation
My personal recommendations for some libraries would be nano-css, fela and free-styler. Glory has made a benchmark to test CSS in JS libraries, this benchmark shows a lot about Fela's performance over Goober, Emotion and Nano-CSS.
There's a lot of differences also in the way the CSS is implemented in the page, some use CSSOM, some use single style tag injections while others use multiple style tag injections (better for 5th gens while worse for 3rd gens). CSS in JS is a whole world where everyone's trying to grab a little of performance in something.
The way I do it in my personal projects are to use nano-css or any 5th generation performant library and implement my own theme system on top of it, using styled-system Styled Props, I love them.
danil-instacart commentedon Nov 26, 2022
That's a lot of great alternatives. Thank you!
@phiberber I ran into this amazing thread when realized that
gooberis not well suited for the CSP policydefault-src 'self' | style-src 'self'since it injects inline<style>at runtime, and there are no rollup/vite plugins for making it generate actual*.cssfiles at build time, the way https://www.npmjs.com/package/mini-css-extract-plugin does it with webpack (not sure ifmini-css-extract-pluginwould ever work withgoober).danil-instacart commentedon Nov 26, 2022
I'm far from understanding the whole landscape of CSS-in-JS, but so far,
linarialooks like the best of all worlds: it's among the most popular ones, lightweight, it correctly extracts*.cssand has the most conventional developer experience with component co-location (pretty similar to hugely popularstyled-components,emotion, etc.) I briefly looked at what is the so-called 5th generation and, honestly, not sold by it so far – probably DX looks too unusual.phiberber commentedon Nov 27, 2022
There's a problem with zero runtime css-in-js that's it has no runtime at all. Dynamic styling is pretty limited because of that, I would recommend Solid-styled-components to look like and act like styled-components, which has a runtime and allows any kind of dynamic prop.
That's why all the recommendations I've made are libraries with runtime. This project probably only exists to extend the Solid ecosystem, that has no problem at all, the problem is making an unpredictable library.
Don't get me wrong, Linaria is really good, but it's not a perfect replacement for styled-components nor goober.
One thing that I had never seen before was an adapter css-in-js system, where one could use the same API with different libraries, just like deploy adapters, if that were the case, I would agree in supporting Linaria.
About the CSS files, it's a big problem that static CSS is generated in runtime when SSRing. I'vent noticed any library yet that allows static css extraction while still running with runtime dynamic styles. Nano-css does have a really good implementation of static vs dynamic styles, but I don't think that would be enough to work with.
It has always been a thought of mine of creating such library, which through partial evaluation is able to determine dynamic styles, in-line static styles and extract them to pure css at build time, while then only delivering the JS of the dynamic styles. I've tried to do that once, but the babel's partial evaluation system had some big problems.
I would be up to help creating such library, but I don't think that's what @ryansolid is planning to this SSC. That's why I still keep my recommendations.
phiberber commentedon Nov 27, 2022
I would also like to add, Solid Start is implementing the Islands Architecture. In my opinion not only Islands are something hard to achieve with a good level of DX by it own, but implementing CSS-in-JS using Islands always turned out to be a mess (to me).
I don't think this project is a serious project. I know it's here to be used, but it has been shown that Ryan is not focusing on SSC. I think SSC exists only because Solid needs ecosystem, Ryan is then trying to deliver that fast, at the cost of using making bad decisions (goober).
If this project were to be serious, I would suggest discussing about the following topics:
It's a lot of discussion and it's all related subjects. Should this be all discussed here in this thread? The islands problem does have a big effect in which library to replace Goober with, being like Styled Components too. I'm really unsure about the future of this issue, it can go to amazing places, it can turn into a mess.
phiberber commentedon Dec 3, 2022
It is also good to mention. Solid Styled Components is currently being used along Styled-System by some people. There's even an issue about it solidjs/solid#148.
When thinking of a goober alternative, it would be good to check for the compatibility of that x library with Styled-System.
I'd also like to know about @ryansolid's opinion on this, it may be too late to change libraries, I'm not in the position to say that though.
Profesor08 commentedon Dec 10, 2022
The only advantage of goober is it size. Class generation is wrong, it not respecting nesting of class and their relations. This is related to recently opened issues: solidjs/solid-styled-components#7, cristianbote/goober#397
There is very very simple example, where this library totaly fails. It was very hard to debug and to find this. I have spent a lot of time to find the issue in my components styling. And there was no issues, styling was perfect, but goober thinks different and broke everithing.
Before you try this example, try to guess the style of all 4 components, on parent element hover.
azuwo commentedon Dec 10, 2022
I think the best option is Linaria or any Zero-runtime library for css-in-js, in fact there is a PR for solid integration in Linaria repo
millette commentedon Dec 10, 2022
@azuwo quoting #40 (comment) from above:
phiberber commentedon Dec 10, 2022
Like I've said and has been quoted. Solid-Styled-Components should in my strong opinion look and act like Styled-Components.
I would recommend a Solid-Styled library to be created to support multiple CSS in JS adapters, which is the idea I've already mentioned here. Then Linaria would really be a good option as an adapter.
I agree that the only good factor of Goober is its size.
phiberber commentedon Feb 13, 2023
@ryansolid Can this issue have your attention? It makes no sense using Solid which is one of the fastest frameworks along with Solid-Styled-Components currently. SSC uses Goober which has been shown to have serious performance issues when updating styles (Like changing from Light theme to Dark theme).
0x241F31 commentedon Jul 20, 2023
@phiberber I made something you can add to your CSS-in-JS tier-list :P
https://github.com/MrFoxPro/vite-plugin-toad
miloofcroton commentedon May 19, 2024
Cool idea. I see it is in maintenance mode now. Do you have a better alternative?
0x241F31 commentedon May 19, 2024
I switched to unocss
mindplay-dk commentedon Apr 14, 2025
"why can't we just" 🥴
okay, bear with me:
the
csshelper would parse the template string and find signal references, generate a stable identifier for each signal (e.g.--signal-123) and then replace signal references with the custom property references.the parent
divwould set up subscriptions to update just those specific custom properties on the parent element.and so, what actually gets rendered would be:
this way, you can update individual custom properties on the element, and a single global stylesheet stays in place.
okay, so this is limited to "things you can do with custom properties", e.g. no conditional CSS - if you wanted that, you'd have to set it up by rendering/removing individual
<style>tags, or using the upcoming native CSS conditionals, etc.but it's potentially a lot simpler and cleaner than parsing and regenerating actual CSS... maybe? 😊
mindplay-dk commentedon Apr 15, 2025
I've been refining this idea, here's where I'm at now:
--solid-123etc.for some use cases (like this button) you'd likely want the element type and class attribute specified by default, so:
the component returned by the CSS factory function is also a proxy that can generate a component with the
asattribute and other props populated with default values.this would work for structured elements like lists as well, and could probably support constant and prop interpolations too:
again, in this example, the
pis a proxy that generates e.g.--solid-123placeholders.the syntax is a bit like styled components, but it is much simpler, since it doesn't really modify the CSS at all.
if you don't like making up class names, maybe we could have it do a simple search-and-replace for
:rootor:scopemaybe? and of course, any CSS features you choose, like nested selectors could be used too:with nested selectors and structures, because it's using custom properties, maybe we could override in nested elements as well - in the example above, there's no reason you couldn't override
$itemColorfor the individual list items. I'm not sure what the most practical syntax would be for that though.of course, as mentioned, this approach is limited compared to styled-components, since you can only do what CSS can do.
I don't know that that's a bad thing though? it certainly eases the learning curve, and likely makes for a very lightweight and efficient implementation.
I'd love to hear your thoughts? :-)
Linaria looks cool as well, if you want to support something existing rather than reinventing the wheel. Personally, I'm questing for something simple, something that stays close to the platform, and provides a single pattern that works well for everything. I'm sure there's still tons of stuff I haven't thought of, so feel free to shoot this full of holes. 😅
mindplay-dk commentedon Apr 15, 2025
A possible proxy based pattern for nested custom property overrides maybe:
the
List.liis a just a proxy generating a function that renders anliand applies any custom properties.mindplay-dk commentedon Apr 15, 2025
for your understanding, this approach stops short of building your components for you - it can build the styles and an element, and help you set custom properties, but it's not styled components... you'd still want a proper component wrapping your styles providing higher degrees of abstraction, for example:
okay, I'm going to stop spamming this thread, but idk... I could see myself using this maybe?! 😄
mindplay-dk commentedon Apr 16, 2025
I've spent a lot of time looking at CSS-in-JS libraries this past week, and I'll just add two more libraries to the pile.
@ryanmorr/fusion
this appears to explore the direction I was presenting above, and it's quite interesting - it's based on the author's own implementation of signals, so the patterns he's come up with are all centered around signals and reactivity, along with the idea that I was peddling above, of essentially coupling signals to custom properties. I quite like the direction he's taking with this, and in all my research on this topic, I haven't seen another library doing this. It's worth a look, I think.
@phantomstudios/css-components
this is based on CSS modules, and honestly, my own personal opinion on CSS modules runs hot and cold, but... this is interesting, because it takes a completely different direction, one of mainly leaving the CSS out of the equation and delegating that to CSS modules, and as such, you could argue it's not really CSS-in-JS, per se. instead, this library focuses on CSS integration at the component level, with abstractions around "variants" and styling of intrinsic elements, etc.
honestly, I've spent almost 3 days straight deep diving on all the various CSS approaches, and I'm honestly not sure what to think - every CSS-in-JS solution seems to have drawbacks or limitations. I think, no matter what you pick, you're going to miss something offered by another solution. I don't think there's an "one size fits all" here - CSS is complex, and UI libraries are complex, and I think, essentially, none of these pieces are to fit together exactly.
personally, I'd very much like to see something that stays reasonably close to the platform, or at least, close to technologies that are reasonably common across the ecosystem. think
@ryanmorr/fusionbut maybe without the CSS preprocessing maybe?Profesor08 commentedon Apr 16, 2025
CSS-in-JS offers a great opportunity to change styles based on component props in realtime. That was a killer feature, at least for me. But they had a lot of drawbacks:
Modern CSS now provides enough support for features like custom properties and :has() selector. Using them, there is no need to use css-in-js.
mindplay-dk commentedon Apr 18, 2025
@Profesor08 what do you use? just plain CSS files? any particular pattern? (BEM? utility-first?)
I would always default to plain CSS for simple web sites - but in an application context, one of the main problems with plain CSS is just simply that of coming up with class names. It becomes quite a meaningless exercise - at least with something like BEM, where you have to name every individual element within a component structure. It's a waste of time, and often really unhelpful to the next person reading the code.
It also gets problematic over time - for example, needing to refactor (again, at least with something like BEM) because your element structure needs to change, it often turns out the CSS is extremely fragile. You can counter some of this with utility classes for styles with structural dependencies (mostly layouts) but you're still stuck with a lot of noisy, unhelpful names, clunky and error prone refactoring efforts, and so on. And all of this compounds when working on a team.
I think custom properties, the
:hasselector, or even things like cascade layers (which make CSS massively more scalable) do not address any of these issues.In a component oriented context (e.g. with most UI frameworks) the components drive the markup structure, so it probably just makes sense to let them control the styling as well, I think. These concerns are naturally highly coupled - there is no real "separation of concerns" you can achieve here, what you get instead is just "fragmentation of concerns".
Almost no matter how you're doing CSS, if you have components, the CSS ends up mirroring the structure of the components. The cascading part of CSS was just more relevant in a time before components, I think.
At least that's my experience, which is why I'm interested in finding a good approach to CSS-in-JS.
In Solid and anywhere, really.☺️
Profesor08 commentedon Apr 18, 2025
@mindplay-dk I switched to CSS Modules. I did some work to configure them in my projects and ensure they bundled correctly. So now, I don't care about dead code, about naming, about relations. If I need to modify some component in scope of another component, I can just pass an additional class name, and this will not break nothing in other places. If I need to modify the component itself, I can do this at any time, and then to check where it is used and easily find where it is broken. Because now is everithing is under control.
nns2009 commentedon Aug 14, 2025
@phiberber, hi! You seem to be extremely knowledgeable in CSS frameworks and furthermore our views seem to align, so I would appreciate your opinion.
What styling solution would you recommend as of 2025 for a mid-scope (4-6 months) project in SolidJS and TypeScript?
I'd prefer a styling solution, where:
I imagine being able to write something like this:
but, I'm not set on it being pure TypeScript. Also open to solutions including style-specific languages.
phiberber commentedon Aug 15, 2025
@nns2009 I'd probably recommend Tailwind to be honest.
nns2009 commentedon Aug 15, 2025
@phiberber Thanks for the answer!
A bit "basic/mainstream" solution, but I guess often it's best not to overthink stuff.
phiberber commentedon Aug 15, 2025
All of these CSS in JS will be most of the times slower than Tailwind, Windi, Uno or similars.
It's not as dynamic, but in the end, it still forces you to follow a pattern that makes your application consistent.
So being less dynamic also has a benefit.
nns2009 commentedon Aug 15, 2025
I see. Rendering speed is my secondary concern, because the app (esoteric coding game) won't be very big. My biggest concern is developer speed/experience, so I can get the project over the finish line.
Yes, totally. At the moment my design is very ad-hoc, trying to get the basic layout of things right, but as a non-mega-experienced designer I see how having some limited options may lead to better consistency and better app.
And LLMs are also probably better at Tailwind compared to lesser known solutions.
mindplay-dk commentedon Aug 16, 2025
At work, we switched from
styled-componentsto Emotion.@emotion/cssis just basic, co-located CSS with JS interpolations, and it's really quite nice - just that would have been fine for me.We also use
@emotion/reactand@emotion/styled, and@emotion/eslint-pluginto enforce some conventions.This a very large React project with tons of screens with custom CSS - Emotion is noticeably faster than
styled-components, so that alone made it worth the switch.If you're concerned about runtime micro performance or bundle size, in my opinion, you're worrying about all the wrong things. Unless you're building a real-time app (games etc.) of some sort, it won't matter - performance of Emotion is just fine, your users will never notice a difference. What will matter is ease of reading, understanding and maintaining the code -
@emotion/cssis literally just inline CSS, so this is not a big decision or any real learning curve, at least not for apps. (for web sites, you might want to think about using something that compiles to CSS - but this is actually a drawback if you're working on an app, because the run-time evaluation in frameworks like Emotion lets you preview changes instantly.)Tailwind just moves complexity from CSS into your markup, which is already burdened with JSX templating/logic - it's too unstructured, mixing too many things into your markup, and it's just too far off from CSS. Set yourself up with design tokens or CSS vars for scales and colors etc. instead. - create a few global utility classes (or yes, borrow them from Tailwind!) for things like flex/grid layout; things that have structural dependencies and therefore actually benefit from being grounded in the markup. Colors, text-styles, borders, shadows, spacing, etc. have no structural dependencies - utilities don't solve any problem for those, and you're much better off seeing
play-buttonorshopping-cartthan a list of 25 meaningless class-names that don't tell you what you're looking at. Just my two cents. 😊As for Solid, I still don't know...
fusionis definitely a very cool idea - if we could have something like this that actually leverages signals, that would seem like a very Solid approach. all-in on signals! But I'm guessing you want things like server-side rendering, so I don't know if this type of approach could easily or naturally accommodate that. Probably not. Linaria does something of that sort for React, I guess - but it's definitely not simple... 🤔nns2009 commentedon Aug 16, 2025
@mindplay-dk thanks for sharing your experience. I'll look into Emotion and fusion.
I am making a game, but not real-time game: esoteric coding game, think like something like SolidJS interactive tutorial, but you also have a list of automatic tests for each task. As I mentioned before, rendering speed is indeed not my concern. I would like to get-rid of "jump cuts" which are prevalent across 99.9% of websites (ideally, nothing on the screen should ever pop in/out of existence without transition), but it's likely to end up being out-of-scope.
I expect the project to take 4-6 months and it being my first solo-dev game without any external pressure, the biggest concern is just to stick with it, get things done and finish it. So:
(+developer speed) is absolutely true for me.
I imagine I might have the ability to share solutions and it would be nice if such pages where indexed by Google, but it's not mission-critical. So far I already had to temporarily disable SSR in Solid Start template for some small reason I don't remember.