joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage
MIT License
975 stars 41 forks source link

Svelte 5 support #230

Closed danawoodman closed 7 months ago

danawoodman commented 7 months ago

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

joshnuss commented 7 months ago

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.

knd775 commented 7 months ago
  • 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.

joshnuss commented 7 months ago

@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.

danawoodman commented 7 months ago

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

joshnuss commented 7 months ago

@danawoodman agree. Feel free to open a PR

webJose commented 7 months ago

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 commented 7 months ago

@joshnuss pr up #233 !

joshnuss commented 7 months ago

@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

github-actions[bot] commented 7 months ago

:tada: This issue has been resolved in version 0.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: