useLocalStorage initial value "undefined" gets written to local storage as string value "undefined"
Coelmount opened this issue · comments
Hector commented
Describe the bug
This looks like like a similar bug to #597
We are doing something like this in one of our components:
const test = useStorage("key", undefined);
As soon as our component is loaded, a key gets written to the local storage with content "undefined" (unless of course something else was set before). The variable test is now containing a string with content "undefined"
When doing:
test.value = undefined
The key is removed and the value is undefined as expected
When using null instead of undefined as default value, it does work.
Reproduction
https://stackblitz.com/edit/vitejs-vite-cv1rhp?file=src%2FApp.vue
System Info
System:
OS: macOS 13.5.1
CPU: (10) arm64 Apple M1 Pro
Memory: 924.95 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.0.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.4 - /usr/local/bin/npm
Browsers:
Chrome: 124.0.6367.91
Safari: 16.6
npmPackages:
@vueuse/core: ^9.7.0 => 9.13.0
vue: ^3.2.45 => 3.4.23
Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.