-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
useStorage
incorrectly handles reactive default values
#4318
Comments
This appears to be the expected behavior - there's a two-way binding between the storage value and initial value. When initial value changes, the storage updates. Correct me if I'm wrong. |
The current behavior is inconsistent and unexpected, for example:
Changing the value in the storage should never affect the default value, regardless of how it is provided. The code below should result in consistent behavior, regardless of how the default value is provided. const data = (shallow ? shallowRef : ref)(toValue(defaults)) as RemovableRef<T> |
@gkubisa Thanks for the summary. It sounds like the expected behavior should be:
Is this understanding correct? |
Yes, definitely. 👍
This one is a bit more tricky and I'm less certain about the best behavior, so here's just my opinion:
|
Just ran into this issue too. I passed read-only |
Describe the bug
There's an issue with
useStorage
when passing a reactive value as the default value. Currently, the composable reuses the reactivedefaults
reference for storing the data. This means that when the local storage value changes, it also updates the originaldefaults
reactive reference, which is not the expected behaviour.Here is where the issue seems to be:
Reproduction
https://stackblitz.com/edit/vitejs-vite-efjb7e?file=src%2FApp.vue
System Info
N/A - Bug can be replicated in any environment
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: