fix(useStorage): Defaults are updated if the storage gets updated when defaults are object like #4784
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Objects are references and when they are passed as defaults, the defaults are directly passed into a ref, and when the ref changes the defaults also change.
E.G:
somewhere else in the codebase:
a workaround is to have a clone of the object (even a getter returning a non cloned object will make the object to be mutated internally):
I tried to implement the structured clone in the composable itself.
a watch is added to check for defaults changes, even tough I don't see a real use case for this feature because i suppose that even if defaults is reactive i am expecting the defaults to be used only when the storage value does not exist, but it seems, that, according to the original implementation, if the defaults change, the storage must be updated for the changed value.
just one small thing had to be changed in a test because now the composable will not return the defaults object when it is a ref but just a clone of it, I don't think this is a breaking change as the final value does not change.
Additional context
Screencast.from.2025-05-29.10-15-52.mp4