-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Unexpected reactivity watching shallowReactive array #9916
Comments
Maybe we shouldn't force deep here if user passes core/packages/runtime-core/src/apiWatch.ts Lines 211 to 214 in a8d0b1b
|
@edison1105 I think we need two changes:
|
Is it possible to fix it based on this PR: https://github.com/vuejs/core/pull/9572/files. It does something similar. |
@edison1105 I added the |
close #9916 --------- Co-authored-by: RicardoErii <‘[email protected]’> Co-authored-by: Evan You <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@yyx990803 This PR is an (unannounced) breaking change in a patch (not even minor!) release!! Before 3.4.2 a shallow reactive was deeply observed, after upgrade to 3.4.2 it is only observed shallowly, leading to observable changes in behavior. Worst, briefly looking at the source change I have the impression that deep observation is not even possible at all anymore! For the philosophical discussion: I think it's not a good change as it ties the behavior of Shallow vs deep is not indicative of where reactive state is, it's more a DX preference for creating reactive state. For example, I default to shallow refs 90% of the time, but I still have nested reactive state. Just because I use a shallow reactive array for perf and predictability doesn't mean I don't put nested reactive state inside that array. Whereas this somewhat made sense in @ragnarlotus example, because everything was located close together and he was in control of both the source and the watcher, it's not always this simple. This can have nasty "changes at distance" effect, consider: 👉 please consider reverting the shallow rule, and merging something like @edison1105 's PR #9572 to let |
@jods4 You can still use core/packages/runtime-core/src/apiWatch.ts Lines 296 to 299 in 8f85b6d
|
@jods4 |
Reverted the shallow default behavior - see #9965 (comment) |
Vue version
3.3.12
Link to minimal reproduction
https://play.vuejs.org/#eNqNVE1zmzAQ/Ss7XMBTCk1yo8TTtM2hPSSdJJ0eQg4EFkwiSxpJ2O54+O9dSQYzHTfTE9Lu27dvP9A+uJIy2fQYZEGuK9VJAxpNL4GVvL0sAqOLYFnwbi2FMrAHhU0M96uSMbG9s2d96lxWpttgDNvSVKuYgrwBBmiUWENICcOCF7xipdbQCAH7ggOAVEKeZTP+XBvV8XYJl7NEURguPk748ww8iDBhSPbBMQuuDYjnlzMyc9zaJJGNmhznfzlGVyUYQ5Ir+DypLyB6tIyxC3+aB61R67JFTSFjsdHjAeGaEB1pY4gWcLn0JY+Biez1Kgp/WSwqoILaFhXWEMI7J/NraTBaWMYh9qE1osygKZnGmKw+WdNzr72XNUXcklzK5rt7lPD44SlxvU42JeuRVFv6hItttEiMuHf9dF1xzZxIy7omxhOEXv7UzkNknvqVogWii8G1ZJSGbgC5XObPvTFE+qliXfVKuzaXTFv3013B3iHSK9GzGm5uH8begFmhXzBUizz1ZMs8lf/kH9UT91VdW+KJ9z84HevqfPngoTrLU7o5a8/cl06sg837RijKFh1GG0PHa9wt6DNNuwgge8XfhHI+ErTfj04YhjxlnWdOHXWeznoXxPRT0tY1XZu8aMHpz3XTKIJKrGXHUN1KOxJKkh3mRD63xt+dzajeLoy3U6XV6wn7iyZVGR1+KNSoNlgEk8+UqkXj3df3N7ij8+Rci7pnhH7DeYdasN5q9LDPPa9J9gzn1H5zbw4t4oO+3hnkeizKCrXIweGLgF6TL2+UfpR7kVy4OFrOYPgDw/GuRw==
Steps to reproduce
Click on
Update Obj1 (should NOT trigger the watcher)
and you will see the message of the watcher having triggered.What is expected?
That the watcher is not triggered since it is watching a
shallowReactive
array and has set{ deep: false }
, so only should trigger when applying changes to the arrayWhat is actually happening?
It is triggeing also when props of objects in the array are changed
System Info
Any additional comments?
#9900
In my case (open source vue project), is causing an extra overhead and lower performance since it is triggering and causing unwanted loop
The text was updated successfully, but these errors were encountered: