-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
watcher for injected value is triggered before destroying the component displayed with v-if="value"
after the value is set to falsy
#6389
Comments
watch
is being executed after the component is (or is supposed to be) destroyedv-if="value"
after the value is set to falsy
in case this is not bug , you can use the watch |
Thanks for the solution, wouldn't it be a breaking change though? I mean technically it isn't, as prior to 3.x/2.7 there was no Working options API examples: 2.7.8, 3.2.27 And last but not least - is there any chance to make it work same like in options API or 2.6 with plugin? This behaviour makes a migration from 2.6 with plugin to 2.7/3.x harder as I have to go through every single watcher and see if it's not affected |
The difference between your initial example and the options API one with3.2.27 is not in the watcher behavior. It's in the way you use Concerning 3.2In your options API example, doing this will not trigger the watcher because this change is never being propagated to children: this.container.foo = undefined reason being: you used the Change your timeout to the following to see how the change will be watched and template: '<sub-component v-if="container.foo.bar" />',
data: () => ({ container: { foo: { bar: true } } }),
created () {
setInterval(() => (this.container.foo.bar = false), 1000);
}, The same codes does not log The reason for 2.7 composition API being different to Vue 2 Options API but working closer to Vue 3 is just that, I presume - being closer to Vue 3.
With a kind of global setting or something? no. |
Thanks for the response, I indeed messed provides, here's updated version for 2.7 and 3.2 (and using I used So I don't really mind Composition API being different from the Options API, the problem is that in
component is destroyed first, and in
component is destroyed after watcher is triggered with
I meant with some patch EDIT: if this can't be fixed then I'm pretty sure that at least this change of the behaviour should be added to the migration guide |
Issue seems to be fixed in latest Vue 2 (probably vuejs/vue@f0057b1 / vuejs/vue#12703) and Vue 3 (probably 78c199d / #2291) |
Vue version
3.2.37
and2.7.8
Link to minimal reproduction
https://sfc.vuejs.org/#eNqFUstugzAQ/JWVLxAJcNojJZWqfkJ79AXI0hAF2/KDHJD/vWtAKE2k9ObdnR17ZjyxD62L0SMrWWVb02sHFp3X70L2g1bGwQTaqLE/YgYGuwxOEKAzaoCE1pK3Dfflm09FR4nSrYCC3zbjNREPIGSrpCWUUnCIrOlu7sfJelma0DDJIiTO6E3f/YDKuzTdweEdUhoUY33xSAwTNLUpwRmqwi6Dl/1+//+Wl0fseolH2nhdNyq+mEDyqXA46EvtMFausr7J203hmPfdQTAiFAw4ISq+wVnGFlPyodbF2SpJ9k6z8nVgBSth7sQeGRNrwU7OaVtybrs2unW2hTI/nE6F8dKRlALtkDdGXS0aIhYsu+Hg1BzR5AZJmUHzjPMO+sAbaYOQgaTcZ/jsq/TyjK3L4Fq79uGj/I19gS45R+uFnJfWpLagCoo2Axt7U3gS0TTRSgi3KYRfpgb7pw==
Steps to reproduce
v-if="value"
)What is expected?
Since the subcomponent is displayed with v-if="value" then when value changes to undefined the subcomponent should be destroyed and the watcher in the subcomponent shouldn't be triggered (and therefore it shouldn't fail)
What is actually happening?
Cannot read properties of undefined (reading 'bar')
System Info
No response
Any additional comments?
Same behaviour can be observed in 2.7 (demo), but not in 2.6 with
@vue/composition-api
(demo) (that's how I discovered the problem)The text was updated successfully, but these errors were encountered: