SolidJS is a declarative UI library for building web applications, much like React, Angular, or Vue. It is built using brutally efficient fine-grained reactivity(No Virtual DOM), an ephemeral component model, and the full expressiveness of JavaScript(TypeScript) and JSX. While understandably no one is really in the market for a new JavaScript UI library, Solid is exceptional, a true standout amongst its competition. These are the 5 reasons you should be at least aware of SolidJS.
1. It's the fastest...
JS Framework Benchmark Feb 2020
Bold claim, and sure some small experimental renderers can pull better numbers in certain cases but Solid is a benchmark king. It's been at the top of the JS Frameworks Benchmark for over a year now, neck and neck with the most optimally hand-written plain JavaScript implementation. This includes surpassing the fastest low-level Web Assembly implementations and this is with a declarative UI library.
And I'm sure at this point you are like what about ____. Go take a look, everyone's there. Solid outpaces Inferno, LitHTML, Svelte, Vue 3.0, React, Angular, WASM-bindgen you name it. (EDIT: Raw imperative WASM is now too close to call)
Into Web Components? It's the fastest there as well according to All the Ways to Make a Web Component
Solid is now the fastest on the server as well. Using the Isomorphic UI Benchmark it has pulled out in front of the competition.
See How we wrote the fastest JavaScript UI Framework, Again
2. It's the smallest...
Realworld Demo Initial JS Bundle Size
While it won't win size in toy demos and benchmark where everything happens in a single Component, that honor probably goes to Svelte, when it comes to larger actual applications Solid has almost no overhead on Components (more like a VDOM library rather than a Reactive one). In so it scales exceptionally. For example, SolidJS currently is the smallest implementation of the renowned Realworld Demo. Its initial JS payload is 11.1kb. This implementation doesn't leave anything out using Context API and Suspense. Svelte's version is 33% larger at 14.8kb. Solid's compiler does a great job of managing tree shaking, its codebase built off the same powerful primitives as the renderer makes the runtime small and completely scalable.
3 It's expressive...
Solid apps are built using JavaScript(TypeScript) and JSX. The compiler optimizes the JSX but nothing else. This means you have the full language at your disposal. You are not limited to premade helpers and directives to control how your view renders (although Solid ships with some). You don't get to rewrite v-for
the way you write a component. There are ways to write custom directives or precompiler hooks, but in Solid it's just another component. If you don't like how <For>
works, write your own. Solid's renderer is built on the same reactive primitives that the end-user uses in their applications.
Solid's reactive primitives manage their own lifecycle outside of the render system. This means they can be composed into higher-order hooks, be used to make custom Components, and store mechanisms. It is completely consistent whether working in local scope or pulling from a global store.
4 It's fully featured...
Solid still considers itself a library rather than a framework so you won't find everything you might in Angular. However, Solid supports most React features like Fragments, Portals, Context, Suspense, Error Boundaries, Lazy Components, Async and Concurrent Rendering, Implicit Event Delegation, SSR and Hydration(although there is no Next.js equivalent yet). It supports a few things not yet in React like Suspense for Async Data Loading, and Streaming SSR with Suspense.
For the reasons mentioned above, it has taken less effort to develop these more advanced features with Solid given its reactive foundation. React clones like Preact and Inferno would require significant changes to their VDOM core to offer the same so it has been a much longer road. And the same is true with new directions React has been doing in its experiments as async rendering and multiple roots are trivial with Solid. In general Solid's approach lets it adapt easily, as it becomes a matter of granularity so it can apply similar diffing as VDOM libraries as necessary and not where it is not.
5 It's familiar...
import { createSignal, onCleanup } from "solid-js";
import { render } from "solid-js/web";
const CounterComponent = () => {
const [count, setCount] = createSignal(0),
timer = setInterval(() => setCount(c => c + 1), 1000);
onCleanup(() => clearInterval(timer));
return <div>{count()}</div>;
};
render(() => <CounterComponent />, document.getElementById("app"));
While a new UI library is supposed to jump out and break the mould. Solid doesn't stand out when it comes to API's or developer experience. If you've developed with React Hooks before Solid should seem very natural. In fact, more natural as Solid's model is much simpler with no Hook rules. Every Component executes once and it is the Hooks and bindings that execute many times as their dependencies update.
Solid follows the same philosophy as React with unidirectional data flow, read/write segregation, and immutable interfaces. It just has a completely different implementation that forgoes using a Virtual DOM.
Too good to be true?
It's the real deal. Solid has been in development for over 4 years. But it is still in its infancy when comes to community and ecosystem. I hope you agree there is great potential here. It's always difficult to stand out in an overcrowded space, and more so for Solid as it doesn't look very different on the surface. But I hope this article gives you insight into why SolidJS is secretly the best JavaScript UI library you've never heard of.
Check it out on Github:
solidjs / solid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Website • API Docs • Features Tutorial • Playground • Discord
Solid is a declarative JavaScript library for creating user interfaces. Instead of using a Virtual DOM, it compiles its templates to real DOM nodes and updates them with fine-grained reactions. Declare your state and use it throughout your app, and when a piece of state changes, only the code that depends on it will rerun.
At a Glance
import { createSignal } from "solid-js";
import { render } from "solid-js/web";
function Counter() {
const [count, setCount] = createSignal(0);
const doubleCount = () => count() * 2;
console.log("The body of the function runs once...");
return (
<>
<button onClick={() => setCount(c => c + 1)}>
{doubleCount(
…
Top comments (25)
I've been using this library for a big project at work and I much prefer it to React.
Although for most of the app the extra speed did not change much, It did make a big difference for screens with large tables or large graphs (drawing dependency graphs with D3). I will be using it
again for another app that I'm starting now.
So my hat goes to you @ryansolid for this wonderful library.
Thank you for a gentle introduction to the library Ryan. I have a quick question about how being fast / slow affects the end user experience, pragmatically? Is it really perceivable to end users? There has to be boundary beyond which everything will be similar for an end user.
Thank you for taking the time to respond. I don't think that in general raw speed is very noticeable in typical cases on typical systems. There has been a decent amount of talk about bundle sizes and low power devices, and even there 10-20kb is only a couple hundred milliseconds. So what difference is it that say Solid renders a 5000 dom elements on a page 50ms faster than React on a Core I7. Sure it's more like 300ms on my Core I5 laptop. Realistically you are only going to notice this on initial load. And then maybe not. What's the difference between 1.4 seconds and 1.7 seconds perceptually? Almost nothing. In the Realworld Demo the gap between Solid and React Redux, the slowest library I tested, was only about 800ms on resource loading under 3G simulation and CPU throttling. Mind you TTI(Time to Interactive) differed upwards of 4 seconds.
Performance is an easy metric, only easier one is kb weight. I started working on Solid because I liked fine grained reactivity as found in libraries like KnockoutJS which had these patterns a decade ago. When I saw React basically copy it with React Hooks (and the Vue crowd finally acknowledge they had these primitives all along), I knew it was a good time to start promoting the approach as IMHO it is much better at doing very similar things by any metric. I created a library DOM Expressions to allow any reactive library(MobX, KnockoutJS, among others) benefit from my work but continued to develop Solid as the pinnacle of this approach.
So while I acknowledge leading with performance sort of cheapens it I hope that if anyone spends the time to look at Solid will see that we have a very well designed and thoughtful approach to effectively build user interfaces.
I really appreciate your work. Thank you.
It may be the best library to use if you want to make a declarative first-person shooter, where performance really matters if you want the best graphics and gameplay mechanics. :D
Svelte seems quite interested in smooth animations, I think that plays into Solid quite well too. I wonder how animations would be best written in solid and how that compares to other frameworks and their popular animation libraries.
Funny enough, I think Solid+Dart could steal some thunder from Flutter. Flutter is just gross, but, Dart is pretty nice TBH. Unfortunately there is the compiler aspect here, so it wouldn't be easy, but at some point any framework needs some answer to Native apps, in some way. NativeScript is interesting but Dart's VM is like WOW amazing. But then you inevitably see Flutter code and I just see all the horrors of Angular+OOP all over again.
I was looking at NativeScript a little. Only my JSX is compiled so it's a matter of figuring out how to best output NativeScript from it. But.. yeah I haven't dug deep at all. If people are interested I'm sure things will go there. I've been a web first guy myself mostly (although I've created and supported a React Native app). I was secretly hoping PWAs would gain more ground quickly by the time I needed to worry about this. But doesn't quite seem like it.
Animations is a place I will need to do more work. Svelte has figured out how to compile it into the template. I can do some similar stuff here but I have less explicit hooks. Svelte basically constructs a minimal lifecycle based components that it uses to anchor different stages of a components life. Solid doesn't really acknowledge components exist and relies on the scheduling of the reactive system. So far I've created solid-transition-group which basically copies React or Vue's equivalent. I've done a few other simple demos with animations but as you can imagine they work today very similar to how they'd work in React or Vue. Using state changes to drive CSS or Web Animations or what ever library you want to use. It definitely isn't as packaged in as Svelte.
I actually don't know all that much about how Svelte does animations, only that animating in svelte was nice. I think mimicking the age old transition-group is great, since it's easier to migrate from react (idk what else people use for animating in react, again, not super well researched on animation libs).
Any thoughts on Dart in general? I've been envision TypeScript as a bridge to Dart, to be honest. I guess I don't know how to gradually convert a codebase to Dart, but my sense is that once you are comfortable with typescript, if you see the Flutter/Dart demo's, it's quite an appealing option over TypeScript. "Add these types, with a syntax built into the language, and get all these extra benefits of faster experience everywhere (super fast hot reloading, AOT compilation, etc)"
It'd be really great to be able to use Flutter Components inside a theoretical Solid.dart, but there might need to be a Flutter-Solid connecting thing akin to react-redux. I'd imagine that any level of HOC-ish Flutter component would be a no-go, however, since the semantics of updating the UI begin to clash (not sure how hard it would be to bridge the two, but surely it's possible in some way)
Dart even avoids any locks during garbage collection, which is amazing. As cool as concurrent mode is, Dart might make concurrent mode/suspense/etc a minor 1% improvement once the performance improvements from Dart are accounted for. Who knows. Just a fanboy.
I honestly haven't had much of an opportunity/reason to look at Dart. TypeScript admittedly was mostly just a pragmatic choice since it seemed like a reasonable thing to do as a library author. It wasn't because of any personal like of TypeScript.
To be fair while the reactivity is a big part of what I do with Solid, my focus on the web came from knowing I could make a tangible difference there. Even SSR wasn't a place I was expecting have such success. I'm not sure how Solid would fit into Dart/Flutter ecosystem as it feels like they already have a good thing going.
I have fanboy'd over dart/flutter, google's presentations on dart/flutter show some amazing tech, but I think Dart is really the star of the show. I look at Flutter code and it's all the horrors of angular all over again.
What I really want is actually-native level performance (AOT compiled dart), great dev experience (dart dev compiler, ddc), BUT in a react/component/jsx paradigm.
Solid gives you that for sure. Also @lume/element gives you one more level higher: custom elements with templating powered by Solid.
I'm also planning to implement JSX for AssemblyScript unless someone else gets to it first, and the compile the implementations of my custom elements to WebAssembly.
The big milestone will be when we can also compile to native (run outside of the browser too, but with a web-first API that is easy for existing web developers).
To be fair I don't really consider CM a thing for raw performance. Unless you are maxing your CPU cycles scheduling is going to be slower for the raw performance. I think of it more of having a distributed way to model possible futures, without trying to coordinate everything directly in the parent.
Over 200ms is where people start noticing it, though I theorize if you can get over 70ms a few people will notice.
Rendering time does factor into SEO rankings, for both bot & hand-tested.
Though with SSR, perhaps none of this matters except for costs if your server time is metered.
Solid's may be faster but the must important thing is that the solid's Dx is much more better than that of React. Solid feels more natural than react and just fits into my head. speed is an added advantage. Solid's reactivity system is much more elegant.
How does it work with legacy apps? The beauty of vuejs is that it can work nicely with apps that have html separated and generated by the server code and also support loading dynamic html to certain extent. When we moved from angularjs 1.x, vuejs was the only option with that kind of support.
I mean Vue does make that easy so it broadcasts it as a use case but any modern library is up to the task as you can set the entry point. You can have a statically rendered site in PHP and then have React control 5 independent parts of the page by importing the bundle and calling
render
after page load on those 5 locations. The reason I imagine we don't hear people talking about this is the build process. Vue lets you just import a script tag and start writing some components. Solid's Tagged Template literals allow you to skip the build process as well.Here's a quick codepen of Solid with no compiler running completely in the browser. codepen.io/ryansolid/pen/KKprxBN.
Although I built Solid with modern browsers in mind. So without polyfills it is not supporting Internet Explorer. Obviously it's pretty easy to make a build with that in mind it just hasn't been a priority. Certain features like proxies are not easily polyfilled so they would not work in that environment anyway.
Vue is very unique and its ability to integrate with external HTML is why I love it. No other framework provides such capability.
Yeah it's a hold out from the old days. KnockoutJS used to do that too with it's HTML string data-binding. AlpineJS and Stimulus do this sort of manipulation as well but only Vue of the modern frameworks offer both this ability and the modern built template setup. One of the benefits from still prescribing to data-binding that is completely HTML compliant.
Great work with the library! Coming from the React world it felt very easy to grab the essence. Was looking for a most performant library with Typescript, JSX and all other goodies and SolidJS hit all the bells. Will give it a try!
This looks so good. Please promote it extensively. Also some good courses on platforms like Youtube and Udemy will help.
I love a lot of things about the library. Definitely going to check it out.
Thanks, will try solidjs
I wonder how it compares to lit-html
In what aspects? There are a lot of considerations. More than I highlighted in this article. I did look for a lit-html Realworld demo when I worked on a previous article but the only one I found was Lit Element + MobX which doesn't seem representative. In a handful of micro benchmarks I've done Solid is smaller but that is inconclusive. Pure performance definitely favours Solid as highlighted in the benchmark above. I've separately done benchmarks where I've shown even out of non-compiled tagged template approaches Solid's tagged template version is faster than libraries like lit-html lighterhtml etc... https://medium.com/@ryansolid/the-fastest-way-to-render-the-dom-e3b226b15ca3?source=friends_link&sk=5ae1688dde789e46cecf5c976e708da5.
Of course there are other things that make comparison difficult as lit-html is a library designed to handle rendering and doesn't worry about components and state management so feature sets are not equivalent. Lit-html has close relationship with Polymer and supported by Google so already a huge leg up. The author also works closely with those working on standards so it is very aligned with the future of the platform. More stars on Github, larger community, and already stable 1.0 release all favourable. Definitely a good library to be looking at.