SolidJS: Reactivity Unchained

Rate this content
Bookmark

Join Ryan Carniato, creator of SolidJS, as he shows off the fundamentals of this unique take on a JavaScript Framework. This session will reflect on the challenges of modern web development that motivated Solid's creation. By retracing his steps from simple beginnings to a full-fledged framework, Ryan will showcase how reactive primitives are the only building blocks you need.

FAQ

Solid.js is a declarative JavaScript library designed for building user interfaces. It is similar to React in many ways but is built on fine-grained reactivity without a virtual DOM, and components in Solid.js only render once.

While Solid.js shares some features with React, such as JSX and function components, it differs significantly in its core architecture. Solid.js does not use a virtual DOM and is based on fine-grained reactivity, similar to MobX and Vue, allowing components to render only once.

Solid.js includes features like portals, fragments, suspension transitions, streaming SSR, custom directives, and data fetching. It also supports primitives such as signals and effects for managing state and reactivity.

In Solid.js, signals are a reactive primitive used to manage state. They consist of a getter and a setter function that encapsulate a value, allowing for fine-grained reactivity by notifying subscribed effects of changes.

Components in Solid.js render only once. Unlike other frameworks that re-execute components with every state change, Solid.js uses a reactive system where only the necessary computations are re-executed when dependencies change.

Yes, Solid.js supports JSX for templating. However, it compiles JSX to real DOM nodes, minimizing abstraction and allowing direct interaction with the DOM, which can lead to performance benefits and simpler code.

Solid.js offers significant performance advantages by eliminating the virtual DOM and using fine-grained reactivity. This results in fewer re-renders, more efficient memory usage, and faster updates, especially in complex applications.

Yes, Solid.js is designed to efficiently handle the complexities of large-scale applications. Its reactive model and efficient update mechanisms make it suitable for high-performance applications with demanding rendering needs.

Ryan Carniato
Ryan Carniato
20 min
20 Jun, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Solid.js is a declarative JavaScript library for building user interfaces that addresses performance optimization. It introduces fine-grained reactivity and avoids using a virtual DOM. The Talk explores rethinking performance and reactivity in web applications, understanding reactivity and primitives, and creating DOM elements and using JSX in Solid.js. It also covers rendering components, sharing state, and the advantages of fine-grained rendering and the reactive approach in Solid.js.

Available in Español: SolidJS: Reactivity Unchained

1. Introduction to Solid.js

Short description:

Solid.js is a declarative JavaScript library for building user interfaces. It is similar to React in some ways, but it has a different implementation. Solid is built entirely on fine grain reactivity and does not use a virtual DOM. The update model and life cycles in JavaScript frameworks have runtime implications. Solid addresses the question of when and what to memoize for performance optimization.

Hi, I'm Ryan Carneato, author of Solid.js, and today I'm going to present an introduction to it. What is Solid? It's a declarative JavaScript library for building user interfaces like so many that have come before it.

Solid on the surface at least is a very React-like framework. It values the same things. Unidirectional flow, read write segregation, and immutable interfaces. It's built on the same building blocks. Hook-like primitives, function components, and JSX. And it has a lot of similar features. things like portals and fragments, suspension transitions, streaming SSR, and some others too. That aren't in React, like custom directives and data fetching.

But there is a but. A rather large one. Solid is sort of nothing like React. Solid is built entirely on fine grain reactivity, similar to MobX and Vue. Its components only render once. And there's no virtual DOM. The whole mental model is completely different. Same values, entirely different implementation. But what does that actually mean? Well, modern front-end web development for years has been about components. Class components, function components, option components, web components. And for good reason. Components are essential building blocks that allow our programs to be modular and composable. However, in almost every JavaScript framework, they have runtime implications. The update model and the life cycles are tied to them. And this has led to basically two views of the world. Either you use a top-down diff like a virtual DOM or a tag template literal. Or alternatively, you rely heavily on compilation to separate creation from update. But both of these still have components that basically run top-down. And this kind of begs the question, when and what to memoize? This is important for performance, because if you're going to call something over and over again, you don't want to repeat the work. There's great talk from Sean at React Comp 2021 that addresses this exact thing.

2. Building a To-Do App in React

Short description:

Your first inkling might be to build your to-do app in a framework like React. But as your program grows, you apply optimizations like memo and use callback. Let's compile it. This is compiled output, similar to what a framework like Svelte would do.

Your first inkling might be to build your to-do app in a framework like React. Kind of like this. Declare some state, and wire it up. But on any change, even unrelated to the to-do list, you'd be re-rendering the whole list. But maybe that's okay. That's why there's a Virtual DOM, to make sure this isn't as expensive. But maybe you still want to optimize. As your program grows, you apply your optimizations, and things may start looking like this. Maybe you add a filter, and some theming.

And there's nothing innately wrong with this. But now we are annotating things with memo, and use memo, and use callback. And adding our dependency arrays, and ensuring that everything runs exactly how we want it to. But it's a bit of a departure from where we started.

So... Let's compile it. And this might be what you'd end up with. To be fair, this is not the code you'd write, this is compiled output, kind of pseudo-code, from an experimental compiler React team is working on. But it isn't actually all that different from what a framework like Svelte would be doing. It's a bunch of shallow referential equality checks, that at every decision point, rerun when your component is marked as needing an update. Common ground is a component update state, then runs an update function, and checks against these memorized values, as shown here in this memcache.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a new web framework from the creators of React Router that helps you build better, faster websites through a solid understanding of web fundamentals. Remix takes care of the heavy lifting like server rendering, code splitting, prefetching, and navigation and leaves you with the fun part: building something awesome!
React Compiler - Understanding Idiomatic React (React Forget)
React Advanced Conference 2023React Advanced Conference 2023
33 min
React Compiler - Understanding Idiomatic React (React Forget)
Top Content
React provides a contract to developers- uphold certain rules, and React can efficiently and correctly update the UI. In this talk we'll explore these rules in depth, understanding the reasoning behind them and how they unlock new directions such as automatic memoization. 
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
Interactive web-based tutorials have become a staple of front end frameworks, and it's easy to see why — developers love being able to try out new tools without the hassle of installing packages or cloning repos.But in the age of full stack meta-frameworks like Next, Remix and SvelteKit, these tutorials only go so far. In this talk, we'll look at how we on the Svelte team are using cutting edge web technology to rethink how we teach each other the tools of our trade.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Solid caught the eye of the frontend community by re-popularizing reactive programming with its compelling use of Signals to render without re-renders. We've seen them adopted in the past year in everything from Preact to Angular. Signals offer a powerful set of primitives that ensure that your UI is in sync with your state independent of components. A universal language for the frontend user interface.
But what about Async? How do we manage to orchestrate data loading and mutation, server rendering, and streaming? Ryan Carniato, creator of SolidJS, takes a look at a different primitive. One that is often misunderstood but is as powerful in its use. Join him as he shows what all the Suspense is about.
From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!

Workshops on related topic

Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Back to the Roots With Remix
React Summit 2023React Summit 2023
106 min
Back to the Roots With Remix
Featured Workshop
Alex Korzhikov
Pavlik Kiselev
2 authors
The modern web would be different without rich client-side applications supported by powerful frameworks: React, Angular, Vue, Lit, and many others. These frameworks rely on client-side JavaScript, which is their core. However, there are other approaches to rendering. One of them (quite old, by the way) is server-side rendering entirely without JavaScript. Let's find out if this is a good idea and how Remix can help us with it?
Prerequisites- Good understanding of JavaScript or TypeScript- It would help to have experience with React, Redux, Node.js and writing FrontEnd and BackEnd applications- Preinstall Node.js, npm- We prefer to use VSCode, but also cloud IDEs such as codesandbox (other IDEs are also ok)
Learn Fastify One Plugin at a Time
Node Congress 2021Node Congress 2021
128 min
Learn Fastify One Plugin at a Time
Workshop
Matteo Collina
Matteo Collina
Fastify is an HTTP framework for Node.js that focuses on providing a good developer experience without compromising on performance metrics. What makes Fastify special are not its technical details, but its community which is wide open for contributions of any kind. Part of the secret sauce is Fastify plugin architecture that enabled developers to write more than a hundred plugins.This hands-on workshop is structured around a series of exercises that covers from basics "hello world", to how to structure a project, perform database access and authentication.

https://github.com/nearform/the-fastify-workshop
Let AI Be Your Docs
JSNation 2024JSNation 2024
69 min
Let AI Be Your Docs
Workshop
Jesse Hall
Jesse Hall
Join our dynamic workshop to craft an AI-powered documentation portal. Learn to integrate OpenAI's ChatGPT with Next.js 14, Tailwind CSS, and cutting-edge tech to deliver instant code solutions and summaries. This hands-on session will equip you with the knowledge to revolutionize how users interact with documentation, turning tedious searches into efficient, intelligent discovery.
Key Takeaways:
- Practical experience in creating an AI-driven documentation site.- Understanding the integration of AI into user experiences.- Hands-on skills with the latest web development technologies.- Strategies for deploying and maintaining intelligent documentation resources.
Table of contents:- Introduction to AI in Documentation- Setting Up the Environment- Building the Documentation Structure- Integrating ChatGPT for Interactive Docs
Build a Universal Reactive Data Library with Starbeam
JSNation 2023JSNation 2023
66 min
Build a Universal Reactive Data Library with Starbeam
WorkshopFree
Yehuda Katz
Yehuda Katz
This session will focus on Starbeam's universal building blocks. We'll use Starbeam to build a data library that works in multiple frameworks.We'll write a library that caches and updates data, and supports relationships, sorting and filtering.Rather than fetching data directly, it will work with asynchronously fetched data, including data fetched after initial render. Data fetched and updated through web sockets will also work well.All of these features will be reactive, of course.Imagine you filter your data by its title, and then you update the title of a record to match the filter: any output relying on the filtered data will update to reflect the updated filter.In 90 minutes, you'll build an awesome reactive data library and learn a powerful new tool for building reactive systems. The best part: the library works in any framework, even though you don't think about (or depend on) any framework when you built it.
Table of contents- Storing a Fetched Record in a Cell- Storing multiple records in a reactive Map- Reactive iteration is normal iteration- Reactive filtering is normal filtering- Fetching more records and updating the Map- Reactive sorting is normal sorting (is this getting a bit repetitive?)- Modelling cache invalidation as data- Bonus: reactive relationships
Build a Product Page with Shopify’s Hydrogen Framework
React Advanced Conference 2022React Advanced Conference 2022
81 min
Build a Product Page with Shopify’s Hydrogen Framework
WorkshopFree
David Witt
David Witt
Get hands on with Hydrogen, a React-based framework for building headless storefronts. Hydrogen is built for Shopify commerce with all the features you need for a production-ready storefront. It provides a quick start, build-fast environment so you can focus on the fun stuff - building unique commerce experiences. In this workshop we’ll scaffold a new storefront and rapidly build a product page. We’ll cover how to get started, file-based routing, fetching data from the Storefront API, Hydrogen’s built-in components and how to apply styling with Tailwind.You will know:- Get started with the hello-world template on StackBlitz- File-based routing to create a /products/example route- Dynamic routing /products/:handle- Hit the Storefront API with GraphQL- Move the query into the Hydrogen app- Update the query to fetch a product by handle- Display title, price, image & description.- Tailwind styling- Variant picker and buy now button- Bonus if there’s time: Collections page
Prerequisites: - A Chromium-based browser (StackBlitz)- Ideally experience with React. A general web development background would be fine.