vue icon indicating copy to clipboard operation
vue copied to clipboard

$subscribe triggered when unrelated store used for first time in child component (Vue 2)

Open wsiota opened this issue 1 year ago • 2 comments

Reproduction

~~https://codesandbox.io/s/pinia-store-usage-in-child-component-triggers-subscribe-in-different-unrelated-store-nvhwq8~~

https://jsfiddle.net/posva/z0qbvLr3/

Steps to reproduce the bug

Click on change

Expected behavior

The watcher doesn't trigger

Actual behavior

The watcher triggers

wsiota avatar Oct 31 '22 14:10 wsiota

This seems to happen with plain Vue 2: https://jsfiddle.net/posva/z0qbvLr3/ but not with Vue 3

it might be a limitation of the reactivity system not using Proxies... I moved it to vue repo just in case

posva avatar Oct 31 '22 18:10 posva

This is an edge case due to Vue 2's new property addition check working differently compared to Vue 3.

In Vue 3 we use Proxy for proper detection, but in Vue 2 we do this by registering the parent object itself as the change source. The deep flag is also causing the watch callback to always run as long as any dependency change. So unfortunately this is an edge case due to Vue 2's reactivity limitations.

yyx990803 avatar Nov 09 '22 10:11 yyx990803