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

useStorage - v9.8.2 introduced breaking change - watcher on nested object triggered despite not changed #2782

Closed
7 tasks done
robinpilz opened this issue Feb 17, 2023 · 11 comments

Comments

@robinpilz
Copy link

Describe the bug

We just updated @vueuse/core from v.9.6.0 to 9.12.0 and it seems like there is a breaking change introduced in v9.8.2 likely to be a bug.

We have a scenario where we store an object in the form of { one: { name: "foo" }, two: { name: "bar" } } in local storage using useStorage.

Then we have a watcher on storage.value.one which resets storage.value.two to undefined.
Then we have a watcher on storage.value.two doing something else
Then we have some select fields updating storage.value.one and storage.value.two

localStorage.setItem(
  "test",
  JSON.stringify({ one: { name: "foo" }, two: { name: "bar" } })
);
const storage = useStorage("test", {});

watch(
  () => storage.value.one,
  (val) => {
    console.log("one changed", val);
    storage.value.two = undefined;
  }
);
watch(
  () => storage.value.two,
  (val) => {
    console.log("two changed", val);
  }
);

With v9.6.0 when updating storage.value.two only the watcher on storage.value.two would be called as one would expect.

With version >= 9.8.2 however the watcher for storage.value.two is called 2 times
then the watcher for storage.value.one is called, resetting storage.value.two to undefined
then the watcher for storage.value.two is called again, with a new value of undefined
and funny thing, storage.value.two in local storage is not even resetted 😃

Reproduction

https://codesandbox.io/s/twilight-sea-33kwm3?file=/src/App.vue

System Info

vue: 3.2.45
@vueuse/core: >= 9.8.2
Browser: Google Chrome Version 110.0.5481.78 (Offizieller Build) (64-Bit)

Used Package Manager

npm

Validations

@rafaellehmkuhl
Copy link

I can confirm the behavior.

@jdk2pq
Copy link

jdk2pq commented Mar 10, 2023

I think this may be related to this issue as well, which still appears to be a problem in the latest release.

@AndreiSoroka
Copy link

I have a not similar but related problem. When used with the Module Federation, the useStore becomes non-reactive

@stale
Copy link

stale bot commented May 27, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 27, 2023
@rafaellehmkuhl
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

The problem persists.

@stale stale bot removed the stale label May 29, 2023
@stale
Copy link

stale bot commented Jul 28, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 28, 2023
@maartenbrakkee
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

The problem persists.

@stale stale bot removed the stale label Jul 31, 2023
github-merge-queue bot pushed a commit that referenced this issue Aug 25, 2023
…2782) (#3091)

Co-authored-by: chenglu <jiale.qiu@unionman.com.cn>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
@Codermar
Copy link

Codermar commented Sep 7, 2023

"@vueuse/core": "10.4.1", has a similar issue described here #3312.
It causes infinite loop

Copy link

stale bot commented Nov 6, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 6, 2023
@6XGate
Copy link

6XGate commented Nov 8, 2023

Well the fix that closed this ticket now prevents useStorage from reading the current value in storage when creating the reactive value. useLocalStorage will be return a reference with an undefined value even if there is a value in the backing store. I'll try to make a repro repo for it and file a ticket soon.

@stale stale bot removed the stale label Nov 8, 2023
Copy link

stale bot commented Jan 8, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 8, 2024
@stale stale bot closed this as completed Jan 15, 2024
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

No branches or pull requests

7 participants