fix(useStorage): read object only when it's serialized differently (#2782) #3091
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
details in #2782
The customStorageEventName is used to synchronize storage across different locations. When a storage stores an object and triggers a change, it also triggers this customStorageEventName, which then performs a read operation. As a result, each time the data is changed, it proxies a new object, leading to the triggering of many unexpected watches.
Additional context
🤖 Generated by Copilot at 7addf79
Fixed a bug in
useStorage
hook that caused unwanted reactivity and mutation when using deep reactive objects. Added a test case to verify the fix.🤖 Generated by Copilot at 7addf79
useStorage
hook (link, link, link)toRaw
function fromvue-demi
inuseStorage/index.test.ts
to access the raw value of the store ref (link)update
function inuseStorage/index.ts
to compare serialized values and avoid updating data ref if new value is an object and equal to current value (link)useStorage/index.test.ts
to assert that storage.setItem is called with expected value and store ref is not changed when modifying a property of a deep reactive object (link)