Dev Discussions: Ryan Carniato of SolidJS on Building “The Tesla of JavaScript UI Frameworks”
Tags: javascript, solidjs, webdev
Published: 2022-05-31 19:15:57

CoderPad’s Corbin Crutchley [recently sat down with Ryan Carniato](https://www.twitch.tv/videos/1275982315) to discuss his work on the hyper-performant UI library, SolidJS – which Ryan dubs “[The Tesla of Javascript UI Frameworks](https://ryansolid.medium.com/solidjs-the-tesla-of-javascript-ui-frameworks-6a1d379bc05e)” for its efficiency and performance.

It’s not often you come across a programmer who used to be a touring musician – but Ryan has experience both slinging code with SolidJS as well as some sweet tunes with his band *Mr. Solid* ([both named after a tasty Canadian treat](https://www.hersheys.ca/allancandy/en_ca/products/allan-solid-milk.html)). 

Ryan has been coding since he was 10 years old and started his software engineering career working .NET. It was during these professional years that Ryan discovered Knockout.js and his passion for creating reactive user interfaces; he’s been working in the JavaScript space “solidly” for the past decade. He learned JavaScript by “going to other websites and viewing the source code,” a method that’s become more challenging with the advent of minifiers and obfuscated code.

## What is SolidJS and what is it used for?

Boiled down to it’s essence, Ryan calls Solid a “state library” that has slightly different primitives than React. Ryan built Solid to have “[blazing-fast performance, declarative nature, feature set, and [a\] small bundle size](https://sabe.io/tutorials/getting-started-with-solid),” all while supporting most major features in React.

Solid is heavily influenced by Knockout.js, which came out around 2010 and was made for creating declarative UIs; it has often been compared to React Components. Both React and Knockout have been strong inspirations for SolidJS – down to Knockout’s tutorials that let you run the code in the browser. 

\> Interested in learning more about the history of front end web components? Check out our blog post on [Web Components 101: History](https://coderpad.io/blog/development/web-components-101-history/)

Solid’s reactivity is based on the concept of a “signal” – per [Solid’s documentation](https://www.solidjs.com/docs/latest), “Signals are the most basic reactive primitive. They track a single value (which can be any JavaScript object) that changes over time.”

The signals are associated with a set of subscribed listeners; when the tracked value changes the signal notifies the listeners and they carry out their respective processing actions. This is a lightweight way to improve reactivity and performance in Solid.

Here’s an example of a “Hello World” in SolidJS:

```javascript
function HelloWorld(props) {
  const [first, setFirst] = createSignal("JSON");
  const [last, setLast] = createSignal("Bourne");

  createEffect(() => console.log(`${first()} ${last()}`));
  return <div>Hello {props.name}</div>;
}

<HelloWorld name="Solid" />;
```

Front end frameworks may be a dime-a-dozen, but Solid lives up to it’s jet-speed reputation:

[![SolidJS process speeds compared to its competitors](https://d2h1bfu6zrdxog.cloudfront.net/wp-content/uploads/2022/03/img_62278f0c87949.png)](https://dev.to/ryansolid/introducing-the-solidjs-ui-library-4mck)SolidJS process speeds compared to competitors



SolidJS is also smaller than a lot of its competition. In an implementation of the [RealWorld Demo](https://github.com/gothinkster/realworld) SolidJS [was able to bundle to just 11.1kb](https://levelup.gitconnected.com/a-solid-realworld-demo-comparison-8c3363448fd8) – about 8% the size of the same implementation using Angular.

[According to Ryan](https://dev.to/ryansolid/introducing-the-solidjs-ui-library-4mck), it’s also fully featured and “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.”

## Differences between SolidJS and React

SolidJS can be thought of as a faster and lighter-weight version of React. They both are declarative and support JSX, but Solid cuts out a lot of overhead processes that allow it to render much faster than React.

### Bye Bye Virtual DOM

You read that right – instead of updating a virtual DOM like React, SolidJS updates the DOM itself. Ryan designed this to increase the speed of rendering as there is now less overhead pushing changes from the virtual DOM to the real DOM. 

You can find more on how Solid does this and more differences between SolidJS and React [here](https://blog.logrocket.com/solidjs-vs-react/).

### Web Components Not Included

While Solid is a great fit to integrate into web components, it actually does not use web components “under-the-hood” to generate component instances. Ryan’s reasoning is that while there are certainly uses for web components, they come with performance trade-offs. He found that for Solid he wanted the lightest possible abstraction for a component, which is simply a function that runs once. 

If you’re interested in learning more about the pros and cons of different web component frameworks, check out this article from CoderPad Developer Advocate Corbin Crutchley [here](https://coderpad.io/blog/development/web-components-101-framework-comparison/).

### More Differences With React

Because of Solid’s ability to utilize functions as the reactivity system, you don’t need to rely on dependency arrays like you do with React’s hooks. That means stale closures are dramatically reduced in the Solid ecosystem.

What’s more, because [Solid has a non-JSX method for declaring UI elements](https://www.solidjs.com/guides/getting-started#no-compilation%3F), you don’t need to have a compiler in order to use SolidJS. Even when using JSX + Babel, you only ever compile the Babel instructions to vanilla JavaScript instructions to create HTML nodes – no `React.createElement` here!

For example, our HelloWorld might look like this before being transformed with Solid’s JSX transform:

```javascript
import { render } from "solid-js/web";

function HelloWorld(props) {
  return <div>Hello {props.name}</div>;
}

render(() => <HelloWorld />, document.getElementById("app"));
```

And after the transform, looks like this:

```javascript
import { template, render, createComponent, insert } from 'solid-js/web';

const _tmpl$ = template(`<div>Hello </div>`, 2);

function HelloWorld(props) {
  return (() => {
	const _el$ = _tmpl$.cloneNode(true);
      	_el$.firstChild;

	insert(_el$, () => props.name, null);
	return _el$;
  })();
}
render(() => createComponent(HelloWorld, {}), document.getElementById("app"));
```

Notice how it’s using all vanilla JavaScript APIs like [`cloneNode`](https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode) and [`firstChild`](https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild).

## Hackers Wanted

Want to earn some cash and learn more about Solid? They’re hosting a Solid-based hackathon where winners can end up with a few thousand dollars in their pockets to help improve the SolidJS ecosystem. Anybody of any skill level can enter and you don’t have to give up your weekend to participate – entries aren’t due until April 7th. 

To find out more about the hackathon, check out the info page [here](https://hack.solidjs.com/). 

## Wrapping Up

Ryan has a very unique and substantial development background which is why it's no surprise that Solid definitely hits its mark in being an extremely fast and lightweight frontend library. If you’re interested in watching the whole discussion between Ryan and Corbin you can find it on the CoderPad Twitch channel [here](https://www.twitch.tv/videos/1275982315). 

Happy Coding!