joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Svelte 5 support

danawoodman opened this issue · comments

I understand Svelte 5 is still a preview release, but I'd love to be able to use this store with it. I believe since Svelte 5 is backwards compatible it should just work adding v5 to the peerDependencies chain.

Could throw together a PR if interested

Hi Dana!

Yes, I'd like to fully support Svelte 5.

Ideally it should support Runes too. But in the meantime, updating peerDependencies is a start.

Since Svelte5 is a major update, I'd like to change a few things too.

  • Remove deprecations: Importing using the old function name writable is still supported, but i'd like to remove that. ie import { writable } from 'svelte-persisted-store)
  • Consider switching to devalue as the default serializer (instead of JSON). Because a common gotcha is using values like undefined and serialization doesn't work as expected.
  • Cookie support: it would be nice if cookies could be supported too, but I need to decide on a solution that works with SSR and CSR. Maybe with Runes it will be easier?
  • Consider switching to devalue as the default serializer (instead of JSON). Because a common gotcha is using values like undefined and serialization doesn't work as expected.

The problem with this is that devalue is very picky and doesn't work with really common things like symbol keys on objects.

@knd775 I feel like devalue's features could be more useful than Symbol keys.

I'm suggesting this, because "try devalue" is a common solution to many support requests.

And keep in mind, JSON will continue to be supported. It just wouldn't be the default option anymore.

I'd vote a minor release with just the peerDep change so people can start using it, then follow up with these other things :)

@danawoodman agree. Feel free to open a PR

Pardon the interruption. Why people serialize undefined? In my mind, if the store's value is undefined, it would mean it needs to be deleted. Serializing and deserializing it seems like a major waste of effort in my ignorant mind. If the store gets set to undefined, I would expect the store to delete from local storage. Anything I'm missing?

@danawoodman I'll take a look

@webJose I agree with you, for nested attributes in an object. The problem is that if you set the root value to undefined, for some reason localStorage.setItem() saves it as a string "undefined".

> localStorage.setItem('mykey', undefined)
> localStorage.getItem('mykey')
"undefined"

But it's not just undefined-handling that makes devalue useful. It also supports Date, Set, Map, BigInt, circular objects, Infinity, NaN

🎉 This issue has been resolved in version 0.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀