You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define a shallowRef state (e.g. const counter = shallowRef({ count: 0 })) using setup stores syntax
Use the store in a Vue component
Update the state using $patch({ counter: { count: 1 }) syntax
The state is updated in store but the reactivity is not triggered
Expected behavior
At step 4, the Vue's reactivity system should trigger
Actual behavior
At step 4, the Vue's reactivity system does not trigger (no watcher/computed run after the state change)
Additional information
In the playground, I tested with two other ways to update the shallowRef's state, and the reactivity still works normally:
constcounterStore=useCounterStore();// Using $patch with update function: trigger reactivitycounterStore.$patch((state)=>{state.counter2={count: state.counter2.count+1};});// Direct mutate the state: trigger reactivitycounterStore.counter3={count: ... };
The text was updated successfully, but these errors were encountered:
This is inherent to how shallowRef work. You can use the other ways to call triggerRef().
That being said, it's possible to make this work by calling triggerRef when a key of a shallow object is traversed for the $patch(patchObject)`. For the function syntax, it's up to the user to properly handle this.
Reproduction
https://stackblitz.com/edit/github-5ayhfs4m?file=src%2FApp.vue
Steps to reproduce the bug
const counter = shallowRef({ count: 0 })
) using setup stores syntax$patch({ counter: { count: 1 })
syntaxExpected behavior
At step 4, the Vue's reactivity system should trigger
Actual behavior
At step 4, the Vue's reactivity system does not trigger (no watcher/computed run after the state change)
Additional information
In the playground, I tested with two other ways to update the shallowRef's state, and the reactivity still works normally:
The text was updated successfully, but these errors were encountered: