←back to thread

Svelte 5 Released

(www.npmjs.com)
390 points begoon | 4 comments | | HN request time: 0s | source
Show context
sansseriff ◴[] No.41890232[source]
Svelte 5 has been very nice to work with over the past few months. Yes, runes require you to think more carefully about lifecycles and updates. And you may end up writing a little more code initially than with svelte 4. But it serves you better in the long run with complex apps. I found a process for gradually turning a simple app into a more complex one that works for me. I iteratively move $state() runes out of .svelte files and into .svelte.ts files where I build a more abstract data-oriented structure for my app from a series of mutually linked classes. Then those runes can be re-imported into the .svelte files, or used and updated wherever you need. If you plan it right, I think it avoids the need for heavy redux-like state management. (at least I think so. I haven't worked with redux much myself)
replies(4): >>41890939 #>>41891144 #>>41891258 #>>41893765 #
1. ansc ◴[] No.41893765[source]
> I iteratively move $state() runes out of .svelte files and into .svelte.ts files where I build a more abstract data-oriented structure for my app from a series of mutually linked classes. Then those runes can be re-imported into the .svelte files, or used and updated wherever you need.

I don’t know exactly how you do this, but it sounds like you are dangling on the global state of the runes. This is DANGEROUS in Svelte and can definitely ruin your day.

replies(1): >>41894469 #
2. DecoySalamander ◴[] No.41894469[source]
Could you elaborate on why it's dangerous? Aren't runes just proxies with some variables in them?
replies(1): >>41894532 #
3. ansc ◴[] No.41894532[source]
Of course! I was very used to SPA, and the convenience of moving a rune/store to an external file meant it could be accessed anywhere (as the post said). With SSR however, if you’re not careful, you can easily leak data: https://github.com/sveltejs/kit/discussions/4339.
replies(1): >>41900930 #
4. rofrol ◴[] No.41900930{3}[source]
Thanks. also this https://github.com/sveltejs/kit/discussions/4339#discussionc...