Skip to main content
View on YouTube to comment and like!

Syntax Video

SolidStart 1.0 First Look: Comparing to React / Next.js

Chapter 1 0:00

Intro

solid start is a meta web framework for building fullstack applications with both JavaScript and typescript and it's built on top of the front-end framework solid JS now solid start just reached version 1.0 a few weeks ago and in this video we're going to take a look at it but we're going to take a look at it from the perspective of a react developer so I've implemented a few apps in both solid JS and react and also in solid start and nextjs and we're going to compare and contrast how things are done in all of these so we're going to look at things like State Management conditional rendering list rendering component updates we're also going to take a look at meta framework features like file based routing data loading client side rendering versus server side rendering and everything in between uh we'll also try to look at things from the lens of uh the world of JavaScript and what's to come for meta Frameworks so let's get into it my name is TJ welcome to syntax so a few weeks ago Ryan carniato the Creator and maintainer of solid JS gave a talk at devor called the shape of Frameworks to come and also released

Chapter 2 0:51

SolidStart 1.0 Release

this blog post that kind of details how solid star works and basically announc that it is in 1.0 so that means uh there aren't going to be any more breaking changes you can trust that if you decide to use solid start for your application you will not run into breaking changes anytime soon uh but if you haven't seen the talk I highly recommend you check it out also check out the blog post that kind of details how solid start works why it exists they talk about how they do file routing they talk about how they do data loading and streaming and really just their perspective on this meta framework thing so yeah like I said check that stuff out but before we dive into solid start and look and see how it works we should take a look at solid JS first because solid JS is a front- end framework that solid start is built on top of so solid JS is to solid start as react is to nextjs so we're going to take a look at how solid JS works and uh I know what you might be thinking not another front end framework uh but this is a good one trust me and if you're a react developer you especially will like it I think uh it has over 30,000 GitHub Stars it's been around for over 5 years it's not just some new JavaScript

Chapter 3 1:31

What is SolidJS?

framework it's been around for a while they know what they're doing and if you're a react Dev it's going to look very familiar so this is your first look at a solid JS component at first glance it looks like react but there are some differences here in that we're using signals instead of state and we have a set interval at the top level you would never do this inside of a react component because react renders uh every time there's a state update and then this interval would get redefined you'd have to put this inside of a use effect there are some some differences in how it's actually working under the hood and if you take a look at their homepage they actually have some some benchmarks here now of course you can't trust every Benchmark but it is interesting to see that solid JS is only slightly slower than vanilla JS and that's because whenever you compile and build a solid JS application to run in the web browser there is no runtime there is no virtual Dom basically the code that you write here gets compiled into highly optimized vanilla JavaScript and so that's why it can be so fast compared to these other front-end Frameworks and uh that's why it's interesting to look at because if

you can write an app like this this the build process kind of takes care of a lot of the optimizations for you you don't have to worry about renders and virtual Dom updates you write your code like this and then when you build it it is as small as possible so you have a really small bundle size and it's also really fast because you don't have a runtime you don't have the virtual Dom so it's definitely interesting to check out let's take a look at an app that I built with both react and solid JS so this is an image search application essentially what you can do is type in a search term it will hit an API get back the response and then lazy load these images onto the page so you can see as I scroll we actually have a gray box that takes up the full resolution of where that image will load into it then loads a low resolution and then loads a high resolution image on top of it so this is a custom image loading component and we're going to look at this implement it both in react and then also in solid JS so the app works exactly the same over here enter the search term hit the API get back the images and then lazy load them as they come into view so

Chapter 4 3:19

Image Search App Overview

Chapter 7 4:44

React Conditional Rendering

Chapter 8 4:54

SolidJS Conditional Rendering

declarative show component so in instead of having like a Turner or an inline expression there we have show and there are a couple of props so this says when loading is true render out this image show also has a fallback option so you can decide what to show when this is false and you'll notice to access this signal we actually need to invoke it so if we take a look here this is actually an accessor or a getter for this state variable so this is the one thing that's going to take some getting used to when you're looking at solid code is anywhere we're accessing these signals they actually need to be invoked instead of directly accessed um and then the other thing to look at is rendering lists so in react we just do a map over that list and then render out this Custom Image loader component for each image but in solid. JS they have a built-in four component where you pass in a list and then it will render something out for each element in that list so on the surface both of these implementations look fairly similar except for like these declarative components and these signal accessors but the major difference here is how the render cycle

Chapter 9 5:13

Signal Accessors

Chapter 10 5:30

React List Rendering

Chapter 11 5:39

SolidJS List Rendering

actually works so if you're familiar with react you know that anytime our state Updates this whole function is going to rerun this is basically our render function and if State changes the whole thing will be re invoked we get a virtual Dom tree that gets returned from it behind the scenes there's a virtual Dom diffing algorithm that figures out how to update the page and then every time State updates happen this whole cycle happens over and over again that is react that's how react works with solid there is no update render cycle like that essentially there are fine grain State updates so what that means is all of this code defined at the top here runs once when this component is created so that's the only time it's going to run is when this component is created and then the only parts of our render function that are ever going to render or rerun are the places where we access those signals so these two spots right here are the only sub trees that are going to ever need to recalculate render based on these State changes and that's kind of a beautiful thing because you don't have to worry about all of this code up here running again and you

Chapter 12 5:57

React Render / Update Cycle

Chapter 13 6:21

SolidJS Fine Grain State Updates

know that the only spots that are going to update or rren are the places where these signals are accessed so now let's take a look at that image loader component here inside of react I'll remind you how the app works basically you search for something hits the API and then we lazy load these images so they start off as gray boxes then they load a low resolution version of the image and then they load a high resolution version of the image so if we look at the code we have an image loader component it takes in this photo object and if we look at the type this is just the API response it has things like width and height and then also this SRC attribute which also has a bunch of of URLs that we can use but we have one state variable the image SRC itself so the image SRC starts off as the empty string and then we load it here on the image that we're rendering out and then when the element comes into view we set it to the small SRC and then load the large SRC behind the scenes and then when the large SRC is loaded we set it to that and we're doing this with a use effect so we have a ref to this image here so we can keep track of when it comes into view and so this use

Chapter 14 7:02

React ImageLoader Component

effect will rerun anytime that photo prop changes or that image ref changes and inside of here we have our load image function we Define our intersection Observer which is how we can determine when it comes into view and we grab that ref here so if we have a value there for the ref of the image we observe it using that Observer and if this component ever rerenders or this use effect ever needs to rerun we need to disconnect that Observer so that way we don't have a memory leak now inside the intersection Observer we first set the image SRC to small we then load the large image and stop observing the intersection of this element and then load image is fairly simple it loads that large image behind the scenes and once it's loaded it sets the large image URL now the one thing I want you to pay attention to here in this react component is the use effect this is one of the the major differences we're going to see with solid. js's we don't have to Define this use effect and the way that we access the ref is a little bit different as well so let's take a look at solid you can see we have a signal here for that image SRC and then the render looks fairly similar you can see that we're accessing that signal right

Chapter 15 8:46

SolidJS ImageLoader Component

here on the SRC attribute now for the ref we can just pass in a callback and get access to it and to me this is one of the beautiful things about being able to Define all of these things at the top level is that everything is in scope right so because all this codes up here is only going to run once when the component is created I don't have to think about like a use effect or think about how I'm going to access all of these variables I can literally Define my intersection Observer at the top level here and then use it right when I get access to that underlying Dom element so right here we're just saying observer. observe I don't have to worry about passing into a use effect or anything like that uh the codes is exactly the same so when it comes into view set the image SRC we'll notee again whenever you set that signal this whole function doesn't rerun literally all that happens is this SRC attribute gets updated we then load the SRC image there and then finally we have a cleanup function so on cleanup is provided by solid JS and in here we're just disconnecting that Observer so we don't run into any memory leaks now for me this is really where things started to click for solid because there have been so many times where I'm working in a

Chapter 16 9:46

Why I Like SolidJS

react component and I have to jump through so many Hoops to get all of my variables in the right spot to like be able to use them within a use effect and then if I have multiple dependent variables sometimes I have multiple effects for really complex codes it starts to get out of hand really fast but solid really simplifies that model so we don't have to think about this update cycle and keeping track of all this stuff we can just in a way treat it like vanilla JavaScript where we just Define things one time and then use them when we need them so this is definitely one of the things I like about solid JS as well now if you want to learn more about solid definitely dive into their docs I just scratched the surface and uh they have a tutorial you can can dive deeper and one of the things I'll also note is that signals don't have to be defined inside of a component so when you're in react things like use State and use effect you can only ever use those inside of a component and there's lots of rules around how you use them they can't be conditional and stuff like that with signals they can be defined anywhere you could literally Define this in a separate file import it into any component and it's still going to work

Chapter 17 10:23

SolidJS Docs

so it's pretty slick definitely check out their docs and their tutorial if you want to dive deeper into solid JS so that was a comparison of solid JS and react now let's get to the main event and probably while you're here let's take a look at solid start versus nextjs so we're going to do this by taking a look at a Hacker News clone so whenever you generate a solid application it gives you the option of generating Hacker News and so that's what we're going to look at and I just recreated the exact same app with nextjs so we can compare and contrast the two so the app has a few different pages we can go to the top news here and it's also paginated so we can go to page two page three Etc we can also sort by new we can look at show Hacker News ask Hacker News and jobs and each one of these Pages behaves in the same way we also have a user page and then also the story page which lists out all of the comments and uh that's pretty much it so we have this app in both solid it behaves exactly the same way and then over here in nextjs so first let's take a look at how things are set up here inside of nextjs we have

Chapter 18 10:57

SolidStart vs Next.js

Chapter 19 11:20

Hacker News Client Overview

Chapter 20 11:47

Next.js Layout and Routing

this layout. TSX file this is kind of our entry point and top level we have our nav component brought in and we also have a suspense boundary so this shows loading Whenever there is a page that is in the process of loading now the top level page actually has a dynamic route so when I'm on the homepage here you can see there's nothing in the URL but if I go to page two it's actually top and so that's what this Dynamic param is stories by default it's undefined so we default the top but then on any other page it could also be set to like new or show or ask and so that's why we have this Dynamic route segment here now in nextjs if you're using App router every route has a folder with param and the route path and then inside of that folder is a page. TSX that actually defines that page and so this is our top level page here inside of nextjs we have some props so we're looking at that Pam stories which uh like I said is either going to be top new show ask or job and then we also have our search prams which might have a page number we're grabbing

both of those values setting a default if it isn't already set and so this is a react server component so we're calling our API which is going to give us back that list of stories and then we render them out so now let's take a look and see how things are set up inside of solid start and one of the things to know about solid start is by design it is very modular so I highly recommend check out that talk from Ryan because he talks about why it's modular and basically how he he came up with this structure but it's cool to see that all the parts and pieces you need for a meta framework are are kind of PC Mill right so you have something that's for the data layer you have a something that's used for bundling in the server run time you have something that's used for routing but by Design you could pick and choose these items so if for whatever reason you don't like how these work you could Implement your own or or eventually there will be some that pop up in the ecosystem that you can start to build your own stack from as well and one of the main pieces here is Vinci which is a bundler and server runtime so if we look at the package.json for solid start you can see that it uses Vinci as its Dev server so there isn't like a

Chapter 21 12:59

SolidStart is Modular

solid CLI or anything like that it's using Vinci and that's a good thing because Vinci itself is built on top of vit and Nitro but what's cool is it's basically a framework for building framework so you can see in their docs that they actually have examples of react server components or serers side rendering and so this basically allows you to do the kinds of things that you get with nextjs but you can kind of like build your own stack with it if you're using react but you can use it with other Frameworks as well and so that's one of the coolest things about solid start is it basically takes all of these pieces to assemble a meta framework but in the future you could swap out one of these pieces if you ever need to or Implement your own if you have better ideas about how this kind of stuff should be done so that's one of the really cool parts now let's take a look at the top level entry point we're going to look at the entry server here this basically starts up the server and it is the shell of the application we then also have a client entry point this essentially just mounts it to the Dom and then we have our app.

Chapter 22 14:26

SolidStart Layout / Routing

TSX now here is where we have our router and one of the other cool things to see is this is literally the only spot in our entire code base where we are importing from solid jsart everywhere else where we import something is either from the router or or the solid JS framework itself so this is literally the only spot that solid start actually appears and it's for file routing so if you take a look at how things are set up here we have this routes folder and then each page is its own file inside of this routes folder but the way we're mounting that into our application is with this file routes component so this gets defined right here and that essentially brings in all of those file routes but this is a declarative router so you could add additional routes that aren't file routes on top of this you also could not use that at all you could Implement your own file router if you really wanted to uh the other aspect of this is you'll see that we don't have to do page. TSX right so uh it uses top level routes and there are reasons why you might like the idea of having a folder with a page. TSX inside of it

like you do with nextjs but if you really do like that you could Implement your own router you could build your own uh file routes router here that actually forces you to use like a page. TSX or something like that and so that's one of the the cool things about solid is how pluggable it is now at the top level here you see that we are bringing in our NAB component and then we also have a suspense boundary so so suspense works very similar to how it works in react essentially if it's children are async components it's going to show this fall back here before it loads those components in now our top level entry point is this stories component here and again it's top level and stories by default could be undefined and that just means we're loading the homepage otherwise we will pull in the specific story type like top new show or ask now you'll see that this component has a route object with a load function essentially this assists with serers side rendering and and loading that data on the server but the main part where we're actually loading data in here is this create async function and so create async actually comes from solid router and this is what gives us either server

side rendering or client side rendering and also streaming of the data so git stories is our function that actually calls the API and in this case it's dependent on both the type and the page now one interesting thing you'll see here is we've actually defined these as functions and that's because of this mental model of this codes is only going to run once when that component is created and so if we want to re access these values we would need to re-evaluate that code which is why we've defined these as essentially like getter functions so that way if the type changes this is going to rerun if the page changes this is going to rerun well let's actually talk about the data loading here because this is one of the cool things about solid as well so in nextjs our Pages here are react server components so by default any page you have is a server component and the only way you can make it a client component is if you explicitly say use client on that component now to see what's happening here we can take a look at the nextjs app and basically as I start to browse around it does use client side

Chapter 23 17:16

Next.js Data Loading

rendering so there isn't a full page rerender here you can see that it's actually using an RSD request when I click around to like users and stories and stuff like that and also if we take a look at the Dom so you'll notice here as I navigate around it's just updating the Dom directly right this isn't a full page refresh so we still technically are getting like serers side render on the initial page load and then it's doing client rendering after that but mainly what I'm talking about is the actual request to the API right because as I navigate around these aren't calling The Hacker News API directly it's calling my back end right and so this this is mainly what I mean here by we would have to rewrite this component uh basically we would need to again have a client component and then that client component could have like a fetch inside of it that actually calls the API check this out inside of solid JS so get stor if we actually take a look at how this is implemented this is just a standalone function that has Ed server on it and what that means is this code will

Chapter 24 18:25

SolidStart Data Loading

only ever run on the server and in in this case we're actually calling The Hacker News API from from here so what that means is if we look at how the data is loading inside of solid it's doing a similar thing and that it's actually making requests to our server to load that data but check this out all I have to do is comment out this used server right here here and now this fetch to this API will run directly on the client so now that we've comment out that used server you can already see it happening here so instead of making those uh calls to the server it's calling The Hacker News API directly so for me this is this is a this is a beautiful mental model for how to actually work with data loading is if you want that code to run on the server just put Ed server inside of it it's not bound to specific types of files literally if this Ed server directive is is inside of a function that function is always going to run on the server and the solid router is going to set it up so th that those are RPC

calls by default and uh right now we have this defined in a separate module but the way to think about this is we could do this in line right I could literally have this component here I could have a little function it all it has to do is say use server and we can make a Fetch and now this little piece of code right here is always going to run on the server and so to me this is another beautiful thing about solid start is I don't have to jump around between uh server specific components and client specific components I can just write my components like I'm used to in solid JS and then the solid router and create async are kind of taking care of making sure that these things only live or run on the server if they need to now other than that most of the differences you'll see in the two apps are similar to what I showed earlier so like inside of solid you have like show and four components and things like that but another thing to look at is prefetching and pre-loading so as I navigate around the UI if I'm going to click on like the user or the comments you'll see that with nextjs by default as I click around it's not going to make

Chapter 25 20:23

Prefetching / Preloading

a request to those items until I've actually clicked on them and they're actually loading now if we look at the codes for nextjs I am using this link component provided by nextjs and that's basically what is able to give us client side rendering right so as I click around these aren't full page refreshes xjs is smart enough to basically load that data over RSC and then render the page here um but we don't get uh pre-loading by default so check out what happens inside of solid JS as I just hover over these links it is basically optimistically fetching the data that's required for them now you might say well I don't want that there there's a way to disable it but it's pretty slick that that this is happens just by default and so now that I've kind of like hovered over all of these links the pages load instantly because it's basically already loaded that data behind the scenes now you could do the same thing in nextjs I do think you'd have to get a little more uh manual with it like you would have to have some like on Hover events to make sure that you're pre-caching and pre-loading that data but it's pretty slick that literally all

we need in uh solid JS is just a link to that page and it automatically handles pre-etching of that data you can see here these are just anchor tags to the next page and then inside the story component links to the comments and the user those are also anchor TXS now let's take a look at the codes for the story page that renders out all the comments here so if we look inside of nextjs we have this stories folder and then a nested bracket ID folder in in the page.

Chapter 26 21:46

Next.js Stories Page

TSX folder and it's pretty straightforward right so we grab the story this is a react server component so it's calling the API on the server and then if there was an error don't show it if there wasn't an error kind of just render everything out um but this is the point where I will complain about solid start so if we look at how things are done in solid the template is a little harder to look at and that's because of these signal accessors everywhere right so this is a signal that corresponds to the story that go Got Loaded in but you'll notice everywhere we access it we have to to invoke it right and so this does start to get cumbersome right so if you have a component with these accessors all over the place it's going to get hard to look at I almost prefer if they had something like spelt 5 or like view where you can do signal. value that might be easier to look at the other thing is we're also combining this with the not null assertion of um of typescript so that makes it even harder to look at you can see inside of nextjs I kind of just already made an assertion here that it's not going to be null so we don't have that all over the place we could clean it up but I will say this

Chapter 27 22:11

SolidStart Stories Page

this is one of the things that isn't as ideal about solid is it takes some getting used to and I'm not sure how I feel looking at a component that has these these signal accessors all over the place so that's it for this first look at solid start version 1.0 and you might be thinking should I use solid start today should I drop everything should I stop using nextjs and start using solid start it depends it definitely depends I'll say that everyone's situation is different right so if you're watching this and you are more of a junior Dev or a beginner maybe you're trying to find a job or maybe already working a job with like react and nextjs it probably doesn't make sense to drop everything and start using solid starter or doesn't make sense to just like rewrite your app in solid start uh because the jobs right now are in nextjs and react because that's what people are using I will say though if you are a decision maker right so if you are a team lead or maybe you're the uh lead technical person at your company that gets to make more technical decisions I would say you you can start to consider solid start whenever you're

Chapter 28 23:08

Should you use SolidStart?

uh choosing the text tack for your next application right I I wouldn't recommend people go out and just rewrite their whole app with with solid start because that's a lot of work and you're probably already invested in in nextjs and their stack and everything else um but if you like what you've seen I definitely recommend exploring it right because there's other aspects that I haven't touched on uh things that that maybe I glossed over so I would say if this interests you dive deeper build something with it and really see for yourself uh if it is something that you like and something you would want to build your apps with now the other thing I'm excited about is this aspect of a pluggable architecture because with this basically Ryan and the solid team have kind of released these ideas out into the world and I think we're going to start to see new competitors to nextjs right so I talked about how Vinci doesn't have to be specifically solid you can use it with react you could use it with you or or anything else basically anything that's supported by vit you can make it work with Vinci and

Chapter 29 24:30

The Future of Meta-frameworks

so what that means is we are going to see competitors to nextjs that are built on top of Vinci right so basically it's going to be a stack that looks like this but instead of solid it's react right and uh that is also going to be interesting to see because nextjs definitely needs some competitors there are some really cool ideas here that nextjs should probably steal but uh if they can't because of technical limitations or uh backwards compatibility and stuff like that it would be really cool if a new framework came along that still used react which people are used to but is is kind of like this pluggable architecture which is pretty slick so that's all I have for you in this video thank you very much for watching all of the code that I showed is open source so check the links in the description if you want to dive deeper into the codes also let me know if you have any questions about uh the code that I showed or or maybe something that I glossed over I'd love to talk about it in the comments and also I don't normally say this but subscribe if if you like what you see we'd love your your sub here on the syntax Channel also

Chapter 30 25:33

Thanks!

turn on that notification Bell and uh I'll see you in the next one [Music]

Quote it with credit and a link. Quoting Syntax