prazdevs / pinia-plugin-persistedstate

💾 Configurable persistence and rehydration of Pinia stores.
https://prazdevs.github.io/pinia-plugin-persistedstate/
MIT License
2.06k stars 119 forks source link

falsy values not persisted when using pick #333

Open JimCronqvist opened 2 weeks ago

JimCronqvist commented 2 weeks ago

Are you using Nuxt?

Describe the bug

Falsy values are not persisted when using pick, but rather filtered away.

Relevant configuration:

persist: { pick: ['selectedIndex'] }

If the value for selectedIndex is 0, the selectedIndex would not be persisted.

From what I can see, this is caused by this line below which filters away falsy values. https://github.com/prazdevs/deep-pick-omit/blob/f71e364a33fd2eb1ce8c0e71b2788f4abe8cee67/src/index.ts#L29

Is it possible to retain those values instead? (probably doesn't matter, but Vuex did keep those and made the upgrade unexpected)

Happy to create a PR in that library for the actual change if it helps, but I wanted to check first unless this was intended behavior.

Thanks for all your work on the plugin!

Reproduction

n/a

System Info

n/a

Used Package Manager

yarn

Validations

prazdevs commented 1 week ago

That's not really intended, check should be indeed more precise and only check for undefined, not falsy values. Feel free to open an issue / PR on the upstream repo. Just gotta make sure everything still works as expected 🫡