Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5 support #230

Closed
danawoodman opened this issue Jan 2, 2024 · 9 comments · Fixed by #233
Closed

Svelte 5 support #230

danawoodman opened this issue Jan 2, 2024 · 9 comments · Fixed by #233
Labels

Comments

@danawoodman
Copy link
Contributor

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
Copy link
Owner

joshnuss commented Jan 3, 2024

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?

@knd775
Copy link

knd775 commented Jan 5, 2024

  • 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
Copy link
Owner

joshnuss commented Jan 5, 2024

@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
Copy link
Contributor Author

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
Copy link
Owner

joshnuss commented Jan 5, 2024

@danawoodman agree. Feel free to open a PR

@webJose
Copy link

webJose commented Jan 7, 2024

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
Copy link
Contributor Author

@joshnuss pr up #233 !

@joshnuss
Copy link
Owner

joshnuss commented Jan 7, 2024

@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

Copy link

github-actions bot commented Jan 8, 2024

🎉 This issue has been resolved in version 0.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants