vueuse / vueuse

Collection of essential Vue Composition Utilities for Vue 2 and 3

Home Page:https://vueuse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useLocalStorage initial value "undefined" gets written to local storage as string value "undefined"

Coelmount opened this issue · comments

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

seems to be fixed. Sorry:

#3595