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

Syntax Video

Svelte 5 is a beast, but is it worth switching?

Chapter 1 0:00

Welcome

welcome to syntax on this what what's going on no I'm trying to be animated because of the it's going to be on video now although should we do fa a little bit of faces

first yeah uh let's just leave all of this in okay welcome to syntax and this is episode number 723 we're going to be talking all about spelt 5 what you need to know what's important what the big picture stuff is and and what it's all about and you know what welcome everybody this is officially the first video episode of syntax now you may have seen some prior episodes being popped up we we decided to just take some of our best episodes of the past couple of months and just throw them up and those those weren't actually recorded as being a quote unquote video podcast so this is going to be the format going forward here and you may see some tweaks along the way and what we're going to be doing here don't fret for all you audio listeners out there uh not much is going to change for you we're not going to be describing things that you're seeing on screen um you know perhaps in the future if we are talking about code we'll be

Chapter 2 0:39

Syntax Is A Video Podcast!

showing some code but we're not going to speak about it any differently than we are currently so welcome Wes how's it going going good pretty stoked to be here I've been uh fussing with my mic and everything have we even like should we introduce Randy or or what at what episode do we introduce Randy maybe we should introduce him on the potluck episode since this is a hasty uh Randy you're just going to have to sit in the shadows for one more episode and then we can introduce you into the next one um that makes more sense I think and likewise if you're introducing any code into your application which you know you're doing all the time you're probably going to want to make sure that you have Aon exception handling tracking because hey if you introduce anything uh you could break your code you know what breaks code writing code and if you write code at all well you have an opportunity to have a bug slip in there and more than just bug tracking I think this goes right along with some of the messages of

Chapter 3 1:52

Brought To You By Sentry.io

spelt 5 um you want to be tracking that speed and the size of your code base and that's one of those things that felt 5 really nails and Sentry can do all of that for you uh you can see exactly you know how fast your application is running in you know what you're serving up to your users at any given point so check it out as sentry.io syntax and give it a try today all right spelt 5 Wes to give you some background here I have been cranking on a real world app uh I've mentioned it a couple times on here it says habit tracking app that part is not important the important part is is that I've been getting my hands real dirty with spel 5 I I've been using just about as as many of the apis as I can in a real world context I've been finding the uh pain points I've been you know really enjoying the experience and then just yesterday I got to talk with the spelt 5

Chapter 4 2:42

Svelte 5 Introduction

team a little bit about well the spelt 5 the spelt team a little bit about spelt 5 and um you know where it's at and and what's going to change so I feel like I have some pretty good info here um big picture here is that most of the API since felt 5 are finalized now granted there could be some new stuff specifically around animations but for the most part you can take a look at runes today in the previews or the docs and have a pretty good idea of what the end result will look like once this stuff is released the the big in my mind and this is not from the spelt team by the way a lot of this is is my thoughts my Impressions that spel 5 is about three things it's about speed Simplicity and size which tracks that it's s spel team if you want to use the fact that spel five is speed we could come up with two more s's if you want and then you could have five things that start triangle a

triangle speed Simplicity and size and you'll see this pop up in a lot of ways throughout the course of this speed it's very fast like very very fast size bundles are very very small we will talk more about that and simplicity in these apis what it's doing is it's essentially taking out a lot of the places in spelt where it felt like there may have been one or more ways to do things and like really nail it down to like here's the way in which you do things now which is great um in terms of Simplicity yeah all right let's hear it I want to know what all these features are because we've got the syntax site and I'm sure I would love to implement some of our new features with these these things and like so it's it's released like right like are we able to update our site to spel I know we updated to spel kit 2 um just a couple days ago this is not released it's still in beta um it may even be Alpha L know it's in the next

flag it's under the next flag now I suspect a released candidate is some is coming sometime in the next month and a half um you know I I would imagine that you're going to get to release candidate phase here shortly so that's good news for anybody who's looking to adopt this stuff that's said I'm running an app in production with this stuff right now using the next version of it and that's not a smart idea but if you're like me sometimes you forgo smart ideas to do fun ideas yeah yeah yeah all right so what are runes tell me I'm dying to know here yeah okay well the Rune kind of refers to the idea that in spel you know how we occasionally had like some weird magic symbols in you had the dollar sign to indicate reactivity right um and sometimes you did double dollar sign signs to get rest props well ruins kind of like takes that idea and defines like all right we have the dollar sign and that's going to be considered like the

Chapter 5 5:45

What Are Runes?

magic symbol it's it's the Rune right it's it's the symbol that indicates hey there's something interesting going on here and it really tackles a couple of big areas one state um ins felt before you could do state by just having a variable or you had a writable or a readable um you had lots of ways of doing state in spelt 5 state is being done through the dollar sign State Rune you create a state and then you can update it uh reactively within a component you can create uh bigger better Global stores outside of components and have them use the exact same apis which was one of the problems before with spelt was that if you're pulling State outside of your component now you're using different apis than if you're working with State locally components yeah that was always a bit funky bit funky and another thing is that like big custom stores become way easier to reason about and work in so

Chapter 6 6:21

$state()

like you'll know that we have a big old custom store for our audio player which many of you have noticed occasionally causes uh annoying bugs here and there and many of that stuff is like when I'm working in spel 5 I'm thinking man that player code's going to be great to refactor it's going to feel awesome to use um using this new state Rune um they're Bas they're based on signals which is something that you don't have to worry about they're under the hood oh that's actually kind of nice you don't have to really know what a signal is you just you still have to know what a variable is right like we're not moving to set state right we're still using mutable variables so if I make a state and it's an array um I can still use push and slice and all my mutating values just fine and it's it's reactive variables correct yes and that's really the benefit of this stuff is is when people ask me very frequently hey it looks kind of like react and and I think it does not feel like react

because one you still get that variable mutating reactivity you get like fine grain reactivity and like let's say you have an object full of a bunch of props you can go in and reactively update just like one of those values right um and because it is signals based um you end up getting a lot of benefit F overall in terms of this fine grain reactivity but in reality again it just it functions one way and once you get used to it it's very very nice in many ways you also have this derived Rune where you can essentially track a rune to have a derived value let's say you have a state value that's two you have a derived value that's uh your state times two that derive will always be in sync with the state value if you update that state value derive will update as well uh that's a really nice way of doing things I think we have that a couple spots on the syntax website where we take our state um and then I

need to like derive some values right like I need to I think in some spots I think we filter an array um depending on on the values and it was always a little bit funky where you had to like sometimes wrap like do the dollar sign colon and then wrap a whole block totally inside of that and then and reach outside and update another state variable this derived is really nice because you can say like okay like it's not a new piece of state but you should be watching uh internally what your pieces of state are doing and I actually went through not the spelt State um signals but I went through the preact signals so if you are ever want to read a fantastic I don't know it's probably 800 lines of code or or 500 lines of code go look at the preact signals it's not only react thing it can be used with vanilla JavaScript and and it's a single single file for the entire library and how they

detect whether variables inside of a derived function are changed is really interesting um it's essentially just watching for variables that change and then say Oh something inside of me changed I must then update my derived value yeah yeah in like view they're called like computed variables um this something that I think works really well I I've been using it quite a bit um you know a lot of the runes kind of videos that people have been showing about describing them show like situations where you know when you console log something your state can kind of get out of sync because of perhaps like it's an enclosure or you're doing some you know you're just trying to understand what this variable is at any given time and I personally don't always hit those but when I do hit those issues they are kind of confusing like why is this value not what I'm expecting it to be and I think a lot of what this state variable or state Rune does besides just giving you

one way to do state is it makes working with State more reliable and generally more flexible there are some things where you have to do Getters inside of like big old custom stores that will be a learning experience for some folks you cannot export A Primitive state so if you do export const uh variable that is a state and that state value is just a string that will not be reactive uh so you have to throw that into an object or a custom store that's something you could do with rables that you can't do anymore um but again these are going to be small learning experiences that people are going to get past and there's there's most likely going to be errors in your vs code that say says hey don't do that do this instead um next is dollar sign props and this is the new way of doing props sorry I just looked at the example before you even explained it and I was like this is I could if you go back to the first episode on spelt I could not understand the export thing of

Chapter 7 11:49

$props()

this felt component so sorry go ahead yeah and you're right and not only can were you like the type of person would be like I don't I don't get this export const props which is how you did a props before and you had to do each prop individually um this dollar sign prop solves so many issues around props being weird and spelt basically you you say let and then you destructure your values out of an object equals props the reason why this rule is that one you can do all of the types for all of your props at once you don't have to type each prop individually so you can pass types in that solves a lot of issues two rest props and felt were reared before if you wanted to get the rest of the props that maybe weren't exported you did this dollar sign dollar sign props now you just use the spread operator like you would in normal Java script that greatly simplifies it that's going to be really handy for like if you have like a presentational component and then you

have like the actual like component that does your functionality often you find yourself passing hot potatoing it just from the presentational component down to the functional component and you're rewriting it many times I found that really frustrating to do and this will allow you just to spread them all down that's something we have been able to do and react for a long time will I have a question you might not you might not know the answer to this is that um is class going to be involved in those props that's one thing that always drove me crazy is you can't pass a a class from a custom component down to the the div unless you name it something like clas with a z Oh man um that is not something I know but I can actually test really really quickly here I'll I'll explain why I want this um so often I'll build a custom component inelt and I want to slap a class on it uh because I

want to style it in a certain way um and you're kind of crossing the like style boundary there where you specify the class that's sort of done in like maybe that's done in your page layout and your page Styles will be applied there and then you go inside of your component and any styles that you write inside of that component will then be applied and it I guess spelt doesn't know that you used a specific class and it's being passed in but I I do find that really frustrating because I often just want to oh I'm using this compon but it's like a a different version of it and and you find yourself just like reimplementing the whole class structure like you make a a prop called is big or uh card layout or something like that and it's just like classes do this already yeah so in the preview I am getting unexpected keyword class when I try to do that that doesn't mean necessarily that that's the way it will be that's a great thing that I think uh

we should ping the spel team about because uh when I was talking to them yesterday they wanted to know about all these little weird things that you could think of and uh that's a good one I don't think you actually are able to destructure the word class because class is a res is a reserve word and that's why react has class name unfortunately yeah yeah okay but if you if you destructure it with a rest like you collect them all with dot dot dot it's probably not in there hey let me um let me actually try that cuz it's not a prop it's a HTML attribute I don't know how they would be able to do like the they they tree shake your CSS so in spelt if you don't if you have a class that is not used in a component and it has a bunch of CSS associated with it spelt doesn't it just throws that CSS out right it's unused and it like it has to be static

Ally analyze so if the class is written in a different file I don't know how they would figure that out and maybe I'm just like not doing it right but I always found that to be a bit of a pain so I'm able to pass class as a prop with rest and that seems to work if you use the rest but you cannot destructure class oop but it is collected in the rest it is collected in the rest and I was able to even output it into a template um I can make this available to anybody who wants to I'm just working in the felt reppel here um so interesting enough um next one is going to be the effect which I think this is the one the Rune effect that um people look at this and they say it kind of feels like react doesn't it and I I'm here to say it does not feel like react because I think the things that feel yucky about the react

Chapter 8 16:41

$effect()

are the uh dependency array and maybe not necessarily knowing what's going to set it off with spelt effect essentially just replaces the dollar sign colon block syntax and that is a good thing in my mind because it's way more predictable another cool thing about the effect is that it's removed entirely from server side rendered code so your server side bundle is smaller um which is great SP can be smart enough to say hey we know this is only going to run on a side effect when something else happens you can run so what that means Wes is since it's removed from your server side code you could throw like a document dot whatever inside of there um oh or an entire client Side Library or an entire client Side Library in their demo they were doing like a canvas style thing and the reason why that rules is because if you've ever worked in react in a serers side rendered contexts you'll know that you can't use use

effect you have to use use isomorphic effect for serers side content or you you know if you try to throw a document anywhere in a react component like that it's going to complain unless of course you're doing these new client side components yeah someone might be asking like like what's who cares about how big your server side functions are your bundles are on the server side right like doesn't really matter does it um and the answer is it actually does matter now that we're going a lot more to like serverless and uh Edge functions the smaller they are the faster they will be parsed and sort of booted up and also there's there's a hard limit to how much code you can put in a serverless function Edge function and you you do end up budding up against them especially sometimes you have these little libraries where you don't expect them to be huge and in the next potluck we have a question exactly on that is to things that accidentally don't get tree

shooken uh can can actually really bloat your uh your end bundle yeah so the cool thing about effect here is again it functions kind of like the react use effect in which it runs when something has changed now what does it run when does it run it's it's not about component rerenders in spelt we're not like thinking about a function recalling itself like you do and react you're thinking more or less is the stuff that's used inside of here uh need to be updated or you know when something happens when something changes that's referenced inside of that effect that effect will need to re run um and so that that's it you don't have to worry about infinite Loops you don't have to worry about dependency of rays another really neat Rune here is the inspect Rune and actually I'm sorry before we get off effect you can actually do nested effects too which is kind of blowing my mind right now and I haven't yeah so in in Rich's example he showed like both the initialization script as well as like the listening

script for a canvas drawing app so an effect would probably be handy if you are watching like let's say you have a name variable um and somebody types into a text box and and changes their name um you might want to write an effect that then updates that value in the database whenever they type on it is that maybe an example of when you'd use an effect maybe um yeah I'm going to tell you what effect pretty much replaces any time you would think about doing dollar sign colon a block okay just you when this code variables change so it's not derived like you're not figuring out new state correct in fact that's a that's a a a thing they want you to know is that like if if you're thinking about changing State you know when something when some State changes doing something when some State changes you probably want to use derived right kind of like

an ad event listener for a piece of State when you want to have a side effect you want to you want to send some data else where you want to log something or maybe not even log we'll talk about the next one yeah but it makes sense and one of the ways that Felts different from react is that you're you're more frequently working with the Dom itself and so I think use effect is going to be particularly useful when working with the Dom itself next is inspect which is kind of like console log but you'll know that because unlike react spelt isn't just a function that runs console log would only run once unless you did the dollar sign colon console log which was obnoxious but it made sense now we have this inspect run which is actually way better than a console log because it gives you context it says oh this was an updated event so in your console say uh component or variable updated or I'll just say updated or init

Chapter 9 21:17

$inspect()

based on what the event was that caused this thing to change so it is essentially a reactive counil log but it gives you a lot of context and there's like more freedom in here where there's even a call back you can throw in a debugger statement in there if you're if you're the type of uh person who loves to use the debugger it works really really well in that context as well oh I like that as well that's again um that's something I use quite a bit is you throw a console log in like the right before you you render and if you want it to rerun when the values change because you want to see what the actual updated values look like um it seems like usually I would think like oh yeah just an effect and put a console log inside of there but this is even one step further because I realize that's something that is super common pretty cool and and that's you know a lot of these things I think at first glance you could say ah maybe this feels like you're adding more complexity but in the end I think every single thing here adds to the Simplicity of of spelt because

there now becomes one way of doing things and that way is both good very good uh easy and very very fast so um I love all of that next up is Snippets that can actually be the fourth s in the five s's that we were talking about speed Simplicity SI Scot Snippets and Scott there we go pentagram with Scott on the top yes I love that uh I love that for me to be included in this fault 5 release um Snippets are are basically inline components um this is something that I know Wes has been asking for for a long time people in react land love to have multiple components per file like maybe you're just breaking up a singular section of a component that gets looped around you don't want to have to create a whole new file a whole new component just to do that the whole rigma rooll of exporting and passing props now you have Snippets which are essentially you're defining a section of code that can be reused as a snippet and then you call it like a function using the at render

Chapter 10 23:03

What Are Snippets?

keyword you do at render the function and you pass in your props um small caveats here you can only pass in one uh argument to this which is fine because if if you need more arguments passed in you just pass them in as an object so not really anything crazy or different there um but yeah I know it's getting there but like okay so now I'm building components with multiple props but then if I want multiple in a file then I got to like I got to move it from multiple props to this like weird object it's not a weird object it's just a object but all right I'll take it cuz I certainly hated having to put things in in a separate file when it's especially with an if else like you have the same component and you want to render you want to render it this way if if this is the case and this way if it's the case and oh I need to render this in two spots now I have to put this whole thing in a separate file uh so I'll take it I think

in practice you'll like it um okay i' I've been using it pretty gratuitously um throughout my app and in fact at one point I think I had like four Snippets in one file and it was really easy to reason about in that regard I have since um chilled out a little bit on the Snippets and moved things into actual components as the application has grown but I think that's a good indication of how you'll probably end up using this stuff right CU often times when you are prototyping you're just trying to throw something down right you're trying to throw it down get it working and then maybe as the application grows and you see oh wait I actually need to use this component elsewhere perhaps I will turn it into an actual component and I bet I don't know if this is the case I don't see it in the thing but I bet you can infer the types from the props object so you could just uh say like you could use typescripts partial type of props I bet I bet that would work so you're not like doing a whole bunch of typing you could

say like all right well this this function is taking a partial or uh pick you're you're picking these two props out of all the props that were passed in so I don't think it it'd be as bad as I'm thinking you're you're not going to have to individually type those props as far as I know um that get passed into the yeah and let me even double check that with my um with my code base right now right now it's not possible to add types to Snippets and the parameters this is something we hope to address before we ship SP five okay because you're essentially just making a function right so it is a function you would have to type the function itself right otherwise they don't know what to pass it or or what the type of the data is coming in yeah that okay cool um another cool thing about Snippets is they can be passed as props so you could have like a wrapper component and you could throw a snippet as a prop and then access that inside of the component itself and the neat thing about this is it kind of replaces the

need for slots because past Snippets are way more powerful than slots were um I think we still need to see some code examples of about what that looks like considering slots are used throughout swell Kad and all sorts of stuff so you know who knows what that is but slots will probably eventually be uh removed in favor of Snippets makes sense I was just about to ask can you pass can you export a snippet um from a file but if you're doing that you probably should just make a component right yes probably I know there there becomes a whole thing there right where at what point does it become a component and if you look at my code base over time you can see that most of my Snippets did become components once I needed more out of them um next up is events and this can be the last well maybe not the last thing here we can move it along though events is um on colon click was kind of a fancy spelt syntax now just becomes

Chapter 11 27:33

What Are Events?

the straight up on click and that's the same with all events for spelt components they all just become the on whatever attribute that exists within the browser right so you're now getting to again align yourself with the browser no more fancy naming special situations there uh kind of like that though and yeah like stood out or what yeah I just I kind of like the the syntax of it I never like the fact that on click was not camel cased yeah I know I get that to and it's just like a right especially like if you have custom events and I just asked them about this yeah this custom events I'm also seeing here the the the pipe to prevent default is gone forever I know I love that let me let me tell you um in my conversation with the spelt team that was like one of the thing because they mentioned it very

clearly in the docs that the prevent default is gone and I had to ask just because I wanted to like truly make sure that it was gone um the way they see it is that you can just do a wrap or function around it and they might even export those from spelt you know it seems like it's not the it's not the same but yeah all of these new features that they've been rolling out are just JavaScript right all of they're they're all JavaScript then now they're getting rid of the custom syntax and they're getting rid of some of the magic what's the what's the spelt 6 endg game here you know the spel 6 endgame I think is more of a focus on these um the simp and it does feel like you're aligning with the way they the way they're describing it is I think it's like magic not magical or something I believe that

was the thing I yeah we're like they want it to feel like magic but they don't want it to feel unpredictable and so a lot of this is like aligning with browser apis and you saw that with spell kit a little bit right their usage of uh progressively enhancing forms you're aligning with real HTML apis you're just enhancing them further last little bit here are two new built-in functions there's a few uh built-in functions to felt like tick is one that um we've used before to you know essentially get the next tick inelt it can be useful in context in which you just want to wait a frame you know yeah like you want to put something at the end of the event Loop so I have I have a package that is incredibly popular called waight that's essentially a promise that resolves after however many seconds you pass it in and I use it all the time for just wait zero and Scott says hey you don't need that spell has it built in yeah and it's great one of my favorite apis I use

Chapter 12 30:02

Built In Functions

it all the time uh when I need it but now there's two new ones called untrack and unate unate just removes reactivity from a state variable something that if you wanted to like really dive into maybe some perf there you have something that you don't need to update you can unate it and untrack I think is actually kind of interesting you use it in an effect but it removes something from being treated as a dependency because remember in spelt you don't have to have the dependency array but let's say your effect is running too often because something is updating inside of your if you want to remove something you use the unrack function and it's interest it's kind of like a reverse dependency array right oh so but only if you want it let me let me think about like how that might might work so you have an effect that is rerunning every single time the name changes um and we also need another variable inside of that effect um but

that variable updates too often right so you say okay like you still pass the data in but don't rerun me when uh I'm when that variable changes only rerun me when the the rest of the tra values are dead on that's nice I could I could see that uh I like oh I have a good example uh Mouse X and mouse y right like you do need the mouse X and mouse y but don't rerun every single time someone moves the mouse you know uh so pass it in but don't rerun yeah those those are nice little performance enhancing one and there's several things that I didn't mentioned like state.

frozen or effect. pre effect. active effect. root there are nuanced topics here that you're not going to need to get into in 99% cases because let me tell you I built a whole app with user accounts and database and I I haven't had to use these once so for the most part these are things that only Advanced users are going to want to dive into and not stuff you're going to need to think about too much so let's talk about the last benefits of this before I give my final thoughts smaller output here's a post from Reddit I migrated 147 components and my output is 55% smaller so that seems like a pretty huge win I I think they just removed a lot of the stuff from spelt just got rid of it just got rid of it yeah um so that that's one of the big things they wanted to emphasize is that um your code probably will be well not probably it will be smaller if you use these new apis okay

Chapter 13 32:42

Smaller Output

and in the eventual situation like who knows if this happens or not but in the eventual situation where signals get added to the browser you would then lose even that much more code from your your end bundle right so that's that's something to think about speed uh it's very very fast I've included the benchmarks here this felt team did want me to let you know that like these benchmarks are you know some people optimize their demos for these benchmarks and therefore you should take all of these benchmarks with a grain of salt but even taking them with a grain of salt spelt 5 version uh next 35 is approaching native vanilla JS speeds all around and compared to react or any of these other Frameworks it it blows them out of the water so it's shockingly fast um I'll say that I'm looking what's what is faster on this Benchmark than spelt 5

Chapter 14 33:31

Speed

so solid is just beside it above it vanilla JS million JS is really the only one that I've heard of on this list right impressive it's impressive it's super duper fast and they wanted me to let you know that it's faster even than this kind of leads you on because it's going to be faster in normal use cases that are not like Benchmark specific use cases right like in real world use cases you're going to notice the speed but they also said the the framework shouldn't be the bottleneck ever that's not going to be your bottleneck it's going to be other things so we're approaching a situation here with many Frameworks whether that is solid or spelt where the framework is not the bottleneck um it's it's that fast uh suspected release like I said hopefully we're going to see an RC sometime before March could be around March who knows um nothing official there there will be a code mod of some

Chapter 15 35:00

Anticipated Release

kind as well to help you update who knows what that looks like but it could probably be taking care of a lot of the easy stuff for you like changing props to be the props Rune who knows um my thoughts overall this stuff kicks ass uh I do like it a lot in usage I think you know there is maybe a little bit of a learning curve but I found myself wishing that I was working in these felt apis when I was working on some of the writable bugs that I was having um I feel like the state's way more predictable easier to reason about it does not feel like react if that's your concern the word effect does not make it react there's a lot of like really spy things about uh this overall you can also try it today at the preview app um I'll have a link to that in the show notes if you want to just get your hands dirty with some of this yourself what about backwards compat with the older apis is it is that stuff going to stick around or is it going to be a big like no you got to move all your stuff over

in one good big go almost nothing is like removed from spelt and spelt 5 so there are situations where you become in runes mode where things don't work anymore so it will allow you to migrate one component at a time and again hopefully with that code mod eases some of the pain if you have a lot of components that you're working with but yeah you can do incremental adoption you could say oh all my new components are going to use this stuff or whatever or you can do it all in one Fell Swoop I have found again most of this time I'm removing code my code feels easier to write and there there's less foot guns I think there's less like weird special circumstances sweet I I think this looks very very simple like it's I feel like I understand it you know not I I've built a couple things in spelt we obviously built the syntax website in spelt and I feel like I know it pretty well but uh this stuff seems very very simple and

very approachable so I'm pretty stoked about it yeah I think when I first saw it I was concerned um and then just like most things with the spelt team after spending some time with it I really truly see their vision and it all feels yeah more simplistic in the end I do have my code base that I'm working on too if you want to see how I'm using this don't judge the code a lot of this is scratchy stuff but um there's there's some like real world examples like in mine I have like a global state store uh of dates and derived dates and Getters and Setters and more complex stuff and so check it out beautiful all right thanks every for tuning in we'll catch you later peace

peace

Quote it with credit and a link. Quoting Syntax