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

useStore not unwrapping MaybeRefOrGetter #3417

Closed
7 tasks done
arnKo opened this issue Sep 20, 2023 · 2 comments · Fixed by #3534
Closed
7 tasks done

useStore not unwrapping MaybeRefOrGetter #3417

arnKo opened this issue Sep 20, 2023 · 2 comments · Fixed by #3534

Comments

@arnKo
Copy link

arnKo commented Sep 20, 2023

Describe the bug

The defaults argument of useStore is typed as MaybeRefOrGetter:

export function useStorage<T extends(string | number | boolean | object | null)>(
  key: string,
  defaults: MaybeRefOrGetter<T>,
  storage: StorageLike | undefined,
  options: UseStorageOptions<T> = {},
): RemovableRef<T>

However the value is not correctly unwrapped in line 148:

const data = (shallow ? shallowRef : ref)(defaults) as RemovableRef<T>

If using a getter function () => T as defaults, data will be: RemovableRef<() => T> instead of RemovableRef<T>.

Reproduction

https://stackblitz.com/edit/vitejs-vite-6bznlt?file=src%2FApp.vue

System Info

System:
    OS: Linux 5.15 Linux Mint 21.2 (Victoria)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 19.58 GB / 31.19 GB
    Container: Yes
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.20.2 - /usr/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 8.19.4 - /usr/bin/npm
  Browsers:
    Chrome: 117.0.5938.88
    Chromium: 117.0.5938.62
  npmPackages:
    @vueuse/core: ^10.4.1 => 10.4.1
    vue: ^3.3.4 => 3.3.4

Used Package Manager

npm

Validations

@arnKo
Copy link
Author

arnKo commented Sep 20, 2023

Additionally, using a computed as defaults results in a warning from vue when trying to set the data: Write operation failed: computed value is readonly

@jizai1125
Copy link

jizai1125 commented Sep 26, 2023

Upgrade @vueuse/core to the latest.

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

Successfully merging a pull request may close this issue.

2 participants