News for hackers. Stuff that matters.
Re:Svelte 5: Runes by lolinder on Wednesday September 20, 2023 @10:59AM (#37585051)
Yes, the API is very similar to Vue's. $state is ref/reactive, $derived is computed, $effect is watch/watchEffect.

> why React was made in the first place, to have only one way data binding and to re-render the entire page in a smart way

This last part is why Vue and now Svelte didn't adopt React's model. Yes, reactivity and two-way data binding give you enough rope to thoroughly hang yourself, but it also gives you a very explicit picture of how and when components will update. React, on the other hand, expects you to trust its smart algorithms, which definitely removes a lot of the pain from day-to-day coding but also makes troubleshooting performance problems harder.

I see the distinction as similar to GC languages vs something like Rust: if all you need is to have an app that does a job and you don't care about how it does it, React is a good choice. If you need to have control over exactly what will update and when, Vue's model gives you fine-grained control over updates that's hard to achieve in React.

EDIT: And with that in mind, it's obvious why Svelte, which prides itself on being lean and fast, would avoid the React smart-but-complicated runtime model in favor of the Vue model.

Re:Svelte 5: Runes by hajile on Wednesday September 20, 2023 @11:17AM (#37585302)
React is the pragmatic answer.

Most devs are of average talent and will hang themselves and everyone else with the stateful webs they weave. Even with careful PR reviews, these things have a way of sneaking in and becoming permanent hinderances.

Performance hasn't been a dealbreaker in most JS apps for years now. What HAS been a problem is getting good code out the door as fast as business needs. MOST React code is disposable based on the whims of the company. The bits that aren't disposable are used enough to justify having them designed and maintained by your best devs who should also have the skill to write performant code.

Re:Svelte 5: Runes by josephg on Wednesday September 20, 2023 @11:25AM (#37585398)
> What HAS been a problem is getting good code out the door as fast as business needs. MOST React code is disposable based on the whims of the company.

I know you're right; but this still deeply saddens me. I want well crafted software. I want the code I write and the code I depend on to be made in a way that holds reverence and honor for the craft of software engineering.

I don't want to be running crappy, badly performing javascript made by average talent in react, that exists to serve someone else's transient business needs. Gross.

[dead]
Re:Svelte 5: Runes by josephg on Thursday September 21, 2023 @04:42AM (#37594876)
I have a friend who's a car guy. He bought some fancy Mazda that he just adores and he takes to the track sometimes.

He's not pearl clutching. He's in love with that car. He keeps it immaculate and he has a sparkle in his eye when he talks about it.

Some people are the same with furniture. They buy super expensive, custom stuff and look after it for decades. Not me! All through my 20s I didn't care at all and my various homes were full of cheap ikea furniture. I had bills that need to be paid, and why should I pay more? Most of it is probably in landfill by now.

I'm not an expensive furniture guy. And I'm not an expensive car guy - I don't even own a car. But I am into software. Software is kind of my thing. When software works fast and well, when its clean, reliable, tested and memory efficient - its the best. I know deep down everything is right in the world.

And, obviously, I hate disposable, cheaply made software. I hate when software runs slowly. I hate seeing my expensive computer working hard to do basically nothing because of lazy code. And I hate running into stupid, avoidable bugs. I don't want to create work like that. And I don't want to use with software like that. When software is laggy and unreliable, my skin crawls and I feel disgusting.

Intellectually, I recognize that there's a place for the cheap ikea furniture equivalent in software. But craftsmanship matters to me. And I personally, hate bad software and I don't want it on my computer.

Does that make me a pearl clutching, elitist snob? Sure, whatever. But I'm done acting like I'm sorry for what I like.

Re:Svelte 5: Runes by rmilejczz on Thursday September 21, 2023 @10:10AM (#37597868)
My comment was meant to be a more humorous jab at my own efforts as a software engineer but in re reading I think it came across as rude and I apologize.

I think if you feel strongly about something you should defend it!

Re:Svelte 5: Runes by avarun on Friday September 22, 2023 @11:24AM (#37613262)
Was not funny at all FYI. Trotting out overused clichés about how little pride you have in your work is never funny.
Re:Svelte 5: Runes by mattgreenrocks on Wednesday September 20, 2023 @06:26PM (#37590991)
Gotta love how people trot out this crap on Hacker News, a place they ostensibly self-selected into.
Re:Svelte 5: Runes by no_wizard on Wednesday September 20, 2023 @11:31AM (#37585481)
it may have been true in the Knockout days, however signals in Solid is very very similar in feel and reasoning to React hooks.

It makes it straightforward to reason about, because you aren't dealing with globals, undeclared deps etc. like in the Knockout days

Re:Svelte 5: Runes by mwcampbell on Wednesday September 20, 2023 @11:59AM (#37585832)
Counterpoint: https://ericwbailey.website/published/modern-health-framewor...

Performance does matter to the people who depend on our products. Can we please stop throwing people under the bus in the name of churning out more crap?

Re:Svelte 5: Runes by hajile on Wednesday September 20, 2023 @12:26PM (#37586203)
The real-world performance difference between Svelte and React outside of the tiny benchmark apps isn't very much. The fact that React can prioritize rendering of some things over others means that it can be slower overall, but still feel faster to users.
Re:Svelte 5: Runes by RussianCow on Wednesday September 20, 2023 @02:46PM (#37588264)
> The real-world performance difference between Svelte and React outside of the tiny benchmark apps isn't very much.

I don't know, IME it's pretty easy to run into bottlenecks with React. To resolve these, you have to spend time optimizing data flow and preventing unnecessary re-renders, and it can be really difficult to trace where an update originally comes from. Svelte and other reactive frameworks give you good performance by default, so it's very unlikely you ever have to do this in the first place.

Re:Svelte 5: Runes by james2doyle on Wednesday September 20, 2023 @05:37PM (#37590567)
I agree with you on this.

I never had to deal with `useMemo` and `useCallback` equivalents in Vue apps. The framework is implemented in such a way that it can let me focus on the task at hand. If I have errors in Vue apps, they are logic errors not "you didn't cater to the framework's rendering model" errors

Re:Svelte 5: Runes by hajile on Thursday September 21, 2023 @07:54AM (#37596306)
What is the actual difference between React and Svelte? People don't actually know, but this isn't like the old days where React offered 10x (or more) performance increase over AngularJS without even trying to optimize. We're arguing "better" using very slim margins.

Looking at the geomean benchmark suite everyone uses, it's 1.33 for Svelte 4 and 1.67 for React. That's a mere 0.2x difference and most of that is due to row swapping performance from React iterating lists of thousands of elements -- hardly typical in most apps.

Your team will make THOUSANDS of decisions in your app that will make WAY more difference than 20%. Incorrectly nest some loops in your data processors and the performance difference will almost instantly outshine the update differences.

And all of this is without mentioning that the React team is working on a compiler that will offer many of the benefits you get from the custom Svelte compiler (though TBH, I dislike needing a special compiler for custom JS).

EDIT: I'd also add that the Stage 2 record/tuple proposal will make comparing props many times cheaper and should give a massive performance boost to React as this comparison is one of the things that slows it down.

Re:Svelte 5: Runes by RussianCow on Thursday September 21, 2023 @01:03PM (#37600570)
The statistical performance difference is somewhat irrelevant. The measure should really be the extra time spent optimizing your code, and that value can be far higher in React than it is in Svelte. It doesn't matter if the raw performance difference is only 20%—if that 20% means the difference between a smooth UX and a janky experience, it's still extra work you have to do with React that you don't need with Svelte.

Now, I'll grant you that it really depends on the project. Building a simple admin interface? This probably won't matter. But for an interactive dashboard with dynamic charts and data being updated in realtime? You're almost certainly going to spend some time making it fast. And optimizing React code is currently a pretty poor experience.

For the record, I'm not arguing that the performance difference alone makes Svelte worth using over React. In fact, I think the developer experience with Svelte is far better, which is (in the majority of cases) a much better reason to use a framework. I just want to dispel this myth that React is so fast that you'll likely never have to think about performance, because I've had to do a non-trivial amount of optimization work on just about every React codebase I've worked on.

Re:Svelte 5: Runes by ricardobeat on Wednesday September 20, 2023 @06:57PM (#37591194)
Not sure what you're basing that answer off, the difference in perceived perf in the average app for each framework is huge.
Re:Svelte 5: Runes by Tade0 on Wednesday September 20, 2023 @03:43PM (#37589065)
I've seen people hang themselves with (or should I say on?) hooks.

Performance was the main issue because one incorrect usage of a hook can make a huge difference.

Re:Svelte 5: Runes by troupo on Wednesday September 20, 2023 @04:09PM (#37589458)
Average devs struggle with useEffect, useCallback, useMemo and other hooks. If anything, Svelte, Solid and Vue are significantly easier.
Re:Svelte 5: Runes by kabes on Wednesday September 20, 2023 @11:19AM (#37585321)
You make it sound like react is a dark box with a lot of magic behind the curtains, but I always found the react model very easy to reason about. Modifying state is explicit and is the only thing that can trigger a rerender. These rerenders can only happen down from where in the tree the state change happens.
Re:Svelte 5: Runes by satvikpendem on Wednesday September 20, 2023 @11:27AM (#37585430)
React is honestly how I used to write my code in jQuery too, for some pages that had a lot of state. Basically, just like in game dev, I had a render() function that I'd call at the end of the file that would re-render everything. The pattern itself is very easy to understand, re-rendering efficiently is the hard part, but for React users today, that's an implementation detail.

Hooks are also very interesting, they're basically functions that run at specific times, or that is to say, they're `f(...parameters, state)`. They hold state inside the function, sort of like a closure.

Re:Svelte 5: Runes by bafe on Wednesday September 20, 2023 @04:04PM (#37589386)
Indeed, seeing hooks as closures helped me to understand how they are use for state management. It's really a "poor man's object" with all the advantages of FP in terms of reasoning about state changes, lack of side effects etc.
Re:Svelte 5: Runes by truetraveller on Wednesday September 20, 2023 @08:13PM (#37591727)
Same here. For complex UIs, I almost always had my own 'render()' function.
Re:Svelte 5: Runes by softfalcon on Wednesday September 20, 2023 @11:24AM (#37585386)
I mostly agree with you.

Unfortunately, many React apps use Relay (another Meta product) and it opens up a world of “magic” that is sometimes a real pain to reason about.

Re:Svelte 5: Runes by satvikpendem on Wednesday September 20, 2023 @11:29AM (#37585450)
What do you mean by "many?" While I like Relay, I've almost never seen Relay used in the wild. It's sad as it's quite an elegant concept; just as you define your props for your React component, you define your "props" coming from the server as well, through the GraphQL notation. I've been looking at ways to combine both concepts so that there is no client- or server-side state at all, it's all just state, from a cache that determines whether to refetch from the server or to keep the state local.
Re:Svelte 5: Runes by softfalcon on Wednesday September 20, 2023 @05:30PM (#37590473)
Maybe it's isolated to me and my work here on this repo:

https://github.com/coralproject/talk

I agree that Relay CAN be simple, but it isn't for what we do. Have a look at this ReplyListContainer and its nested Relay logic. I didn't originally write this, but I can see what they were trying to do and how Relay made it difficult for them. Your thoughts are welcome, I won't judge you for being critical of our code and welcome any other Relay dev's opinions.

https://github.com/coralproject/talk/blob/develop/client/src...

Re:Svelte 5: Runes by kabes on Thursday September 21, 2023 @01:24AM (#37593500)
Relay tries to solve the problem of: let a component define its (server) data dependencies. It indeed does this with more magic. But it's not exactly the same problem and you can't really fault react for it. It's also a problem other frameworks don't try to solve.
Re:Svelte 5: Runes by ttfkam on Wednesday September 20, 2023 @12:26PM (#37586207)
Let's be honest: the state (see what I did there?) of React state management is a dumpster fire.

https://fe-tool.com/awesome-react-state-management

That's an article listing the top 18 state management libraries for React.

18?!?

React devs can't even agree on a common development model for state, but you think it's explicit and very easy to reason about?

Folks don't adopt utility libraries for things that were already easy to reason about on their own. I'm glad you've found peace with React's basic notion of state, but it's a far cry from optimal. And the "state ecosystem" of React is a dumpster fire. Layers upon layers of madness that acolytes peer through and proclaim insight.

> These rerenders can only happen down from where in the tree the state change happens.

Yes, after it has DIFFED the whole tree to see where the changes occurred in the first place. Madness. Layers of utter madness.

Re:Svelte 5: Runes by hajile on Wednesday September 20, 2023 @12:36PM (#37586336)
React isn't a state manager and why should everyone be forced to use the one "blessed" manager?

Despite there being so many, only a handful (redux toolkit, jotai, zustand recoil, and mobx) see much real-world use and they are basically just 3 approaches (reducers, signals, and directed graphs) with varying levels of complexity and features.

> Yes, after it has DIFFED the whole tree to see where the changes occurred in the first place. Madness. Layers of utter madness.

Not true. It only needs to diff the leaves of the part that changed and some of those sub-trees can be skipped too if they are functionally pure (or uses shouldComponentUpdate). This is how they reduce complexity down from O(n^3) to something generally closer to O(n)

Re:Svelte 5: Runes by Exuma on Thursday September 21, 2023 @09:12AM (#37597133)
I use vue, so I’m assuming that is the “signals approach”. I use pinia btw

Can you explain how all 3 state mechanisms you mentioned, and how they are different ?

Re:Svelte 5: Runes by rmilejczz on Wednesday September 20, 2023 @12:40PM (#37586398)
I’ve written a lot of react apps (first used it in a hackathon in 2014) and this list is really just fluff. hooks + context make all of these libraries pretty much unnecessary for most react apps as they are not that complex

I think the more glaring criticism is the lack of any unified component library. The amount of different Button implementations alone is astounding

Re:Svelte 5: Runes by eropple on Wednesday September 20, 2023 @01:50PM (#37587338)
I agree on both points. I used to quite like Redux but, between NextJS simplifying the page model and hooks/context being a lot easier for CRA-style apps, I just don't need them anymore for the sort of things I do.

The real kick to the shins is that React Server Components did a number on most component libraries, too. I've been forced to go to Tailwind (and DaisyUI, which is pretty nice) just so my stuff doesn't require 'use client' all over the place. The end result will be way better, it already is when you actually can get there, but right now it's annoying and awkward.

Re:Svelte 5: Runes by WorldMaker on Wednesday September 20, 2023 @06:46PM (#37591120)
That was something that React Server Components definitely got backwards. The default state of the world before RSC was client components. If a mark is needed it should have been "use server" for the new style of components.
Re:Svelte 5: Runes by eropple on Wednesday September 20, 2023 @09:18PM (#37592163)
I don't mind that, because I think server components should be the default. They're better. But the profusion of CSS-in-JS solutions (which always seemed unwise to me) take it on the chin because of it.
Re:Svelte 5: Runes by bafe on Wednesday September 20, 2023 @04:02PM (#37589350)
I just write my first fairly complex react app. As a mostly backend/tool Dev with good knowledge of functional programming I agree with this. I could solve almost any problem using hooks + context and memo. I briefly considered using Redux but I quickly realised that a few changes in certain components would take care of most of my state management problems
Re:Svelte 5: Runes by satvikpendem on Wednesday September 20, 2023 @04:11PM (#37589488)
> hooks + context make all of these libraries pretty much unnecessary for most react apps as they are not that complex

To be fair, context is not a state management tool [0], an article by acemarke, the Redux maintainer. It does work as a dependency injection tool and for many people, that's enough, but it's not a true state management tool.

[0] https://blog.isquaredsoftware.com/2021/01/context-redux-diff...

Re:Svelte 5: Runes by bafe on Thursday September 21, 2023 @02:00AM (#37593745)
React context is is just a way to bridge props deep down a component hierarchy. By combining it with an appropriate hook you can almost obtain the effect of a state manager like redux. There are limits to this however; being just a way to pass props it doesn't give you any fine control over reactivity
Re:Svelte 5: Runes by satvikpendem on Thursday September 21, 2023 @02:03AM (#37593769)
Yes, that is indeed what the article I linked says.
Re:Svelte 5: Runes by rmilejczz on Sunday September 24, 2023 @02:15PM (#37635672)
I did hooks + context, not just context. Hooks + context together can be cobbled together into an adequate state management solution for most apps, this article even agrees with me. So not sure what your point is lol
Re:Svelte 5: Runes by jakelazaroff on Thursday September 21, 2023 @12:25AM (#37593205)
> That's an article listing the top 18 state management libraries for React.

> 18?!?

I mean, the top library has more weekly NPM downloads than every other library in the list combined.

> Yes, after it has DIFFED the whole tree to see where the changes occurred in the first place. Madness. Layers of utter madness.

That is not how rendering works in React.

Re:Svelte 5: Runes by satvikpendem on Wednesday September 20, 2023 @11:02AM (#37585091)
Now if only we had an analogous borrow checker in Vue and Svelte so that we don't hang ourselves with 2-way binding. That might a good research project, actually.
Re:Svelte 5: Runes by jauntywundrkind on Wednesday September 20, 2023 @11:17AM (#37585300)
React & redux both come standard with tools to dynamically observe behavior. A flurry of updates is easy to pin down & fix.

Static analysis seems like a nice to have. All in all I class this category of concern as very far down the list of concerns, one way or two way. Yes bad things are possible. But the martial attitude that oh no people will do it wrong this tech is horrible is, in my view, actively harmful.

99.99999% of times it goes great. We don't need to make coding environments were bad things are impossible.

Re:Svelte 5: Runes by satvikpendem on Wednesday September 20, 2023 @11:31AM (#37585476)
> 99.99999% of times it goes great.

I'll disagree with you on that. I've seen and used enough 2-way binding in various projects to know that even the best of devs can create tangles of effects everywhere. At some point, you gotta blame the tool for having footguns, which is why Rust was created over C and C++, to solve such footguns. In the same vein, something like that should be made for frontend frameworks too.

Re:Svelte 5: Runes by ttfkam on Wednesday September 20, 2023 @12:32PM (#37586296)
But have you used 2-way binding with a more modern framework? Or are you still hanging on to your experience with a defunct framework like Knockout from over a decade ago?

And don't get me started on React's "put all the logic you want in our templating language that doesn't even target HTML5" elephant-footgun. Oh! Sorry! Forgot that React's footguns are aKeats elegant and reasonable while everything else's footguns are dealbreakers.

Re:Svelte 5: Runes by RussianCow on Wednesday September 20, 2023 @02:50PM (#37588343)
> And don't get me started on React's "put all the logic you want in our templating language that doesn't even target HTML5" elephant-footgun.

Sorry, but how is JSX a footgun? I have a lot of issues with React, but JSX doesn't even come close to making the list.

Re:Svelte 5: Runes by ttfkam on Wednesday September 20, 2023 @03:27PM (#37588838)
You obviously keep the amount of JS logic to a minimum in your templates. I have encountered many React codebases that did not do this.
Re:Svelte 5: Runes by jddj on Wednesday September 20, 2023 @12:19PM (#37586105)
I'm replying to you, but I'm asking the room: what, if anything, stops vue3 from compiling down to pure JavaScript like svelte does and reaping the speed benefits?
Re:Svelte 5: Runes by MrJohz on Wednesday September 20, 2023 @04:02PM (#37589355)
I think the main thing is the existence of alternatives. Svelte is cool, but it has the key flaw that the more Svelte you write, the more compiled code appears - generally, Svelte compiles to a size somewhat larger than the original source file.

For Svelte as an "island" tool (i.e. for building islands of interactivity in otherwise static pages, like, say, graphs for the New York Times), that's not a problem, because the extra generated code is made up for by the lack of a bulky runtime dependency. But if you scale that up to complicated SPAs - which has been Vue's main stomping ground - you can end up shipping larger files with Svelte than with other small frameworks.

That said, SFCs in Vue are an ideal source for compile-time compilation, and my understanding is that they're heading more down the route of SolidJS. SolidJS has a similar goal of using a compile step for optimisation, but it leans on its signals library implementation much more heavily, which means the compiled code tends to be much smaller, but you also need to include a runtime. (In practice, there's not much size difference between Svelte and SolidJS at all, but it shows itself at the more extreme ends of very small components and very large apps.)

Vue already has a runtime that's very similar in some ways to Solid's (read: it's all signals, baby), so adopting the rendering ideas from there is an obvious next step. That should drastically speed up rendering, as well as reducing bundle sizes significantly. They've already demoed this a bit, but I think it's not fully released yet - they gave a name for the new system, but I've forgotten what it's called.

Re:Svelte 5: Runes by jddj on Wednesday September 20, 2023 @05:29PM (#37590468)
This is exactly what I was looking for, cheers.

Looks like early experiments were called Vue 'vapor'

Re:Svelte 5: Runes by rich_harris on Wednesday September 20, 2023 @05:45PM (#37590657)
> the more Svelte you write, the more compiled code appears - generally, Svelte compiles to a size somewhat larger than the original source file.

This is one of those things that's more of a problem in theory than in practice, but nevertheless it's worth mentioning that Svelte 5 output is _much_ smaller than Svelte 4 output.

Re:Svelte 5: Runes by MrJohz on Thursday September 21, 2023 @01:26AM (#37593513)
I assume that the Svelte 5 output is smaller because more stuff is being handled internally by signals, rather than the compiled output. Does that mean that the shared "runtime" code is larger, or have you just managed to shrink everything down here?

I'm very impressed by this stuff - I'm still not sold on the implicit reactivity, but I'm really excited about the pressure this is putting on the ecosystem as a whole and where that's going to go.

Re:Svelte 5: Runes by berkle4455 on Wednesday September 20, 2023 @12:45PM (#37586479)
What is the difference between $derived/computed and $effect/watch?
Re:Svelte 5: Runes by lolinder on Wednesday September 20, 2023 @05:17PM (#37590305)
I don't know about in Svelte, but in Vue watch is for taking some sort of action when things change, while computed is meant to return a value.
Re:Svelte 5: Runes by jbergens on Thursday September 21, 2023 @12:14PM (#37599828)
There was/is a state management lib called Mobx that was released years ago and was usually combined with React. It was kind of reactive, very easy to use and fast. It normally only updated the components that was effected by a state change.

It was a bit sad that it didn't get more popular and possibly improved. Some devs liked it but we were a minority compared to those who liked/used Redux.

One strange thing they did was to release a new "version" called Mobx State Tree which was very different. It had a great api but was different and slower.