-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the problem
I asked this question on Discord https://discord.com/channels/457912077277855764/1310259142572900363 but since it did not get much attention, I’m asking it here again.
I have a library that mounts Svelte components directly into DOM (related to rich-text) and I manage these components manually. Previously, I could just run new this.component and then this.component.$set(props) whenever the props changed.
With Svelte 5 however, this has been deprecated. There’s no more a $set method on component, frankly the return type of mount often indicates there's nothing on it. I don't know who decided that the return type of mount should be the generic exports property, but it really makes it hard to see directly what's a regular object and what's a mounted Svelte component.
Anyway, so previously $set worked but now the docs suggest that I should use runes instead:
For $set, use $state instead to create a reactive property object and manipulate it. If you’re doing this inside a .js or .ts file, adjust the ending to include .svelte, i.e. .svelte.js or .svelte.ts.
Which apparently sync themselves automatically without ever needing to use $set anymore. Well, this is fine and all but did the authors consider the implications of this matter? Since runes are only allowed within Svelte components or weirdly suffixed x.svelte.ts files, you can't use them in a library that's bundled into single export.
Well, unless you like naming that index.svelte.js as well OR exporting everything separately as ESM. But to me this seems just so hacky and error-prone as there's no guarantees this file-renaming will work flawlessly with the many file-bundling pipelines out there. The fact that you can't, in any shape or form, update the props directly anymore seems weird.
To fix the errors, I ended up switching to svelte/store Writables instead. Which then produces another problem, namely the boilerplate. All my props have now Writable<x> signatures and in general, are much more inconvenient to use than normal TS types.
Describe the proposed solution
What I’d like, is to maintain my previous code (without any writables sprinkled in) but also the file names as they are.
If component.$set is, for some reason, so terrible that it can't be undeprecated, I'd wish there were a way to use runes without the suffixing of files. Just directly importing maybe from somewhere and using them like writables.
Importance
would make my life easier