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

Unexpected update on app.vue caused by calling computed on mounted #9046

Closed
jackylam1985 opened this issue Nov 9, 2018 · 3 comments
Closed
Labels

Comments

@jackylam1985
Copy link

Version

2.5.17

Reproduction link

https://jsfiddle.net/je3odvk8/

Steps to reproduce

Try click "parent button" which update the parent component's data, but I don't understand why this causes app to update. But if you remove the line #32 console.log(this.childName), this won't happened.

What is expected?

Expected only updating the Parent component and Child component when data updated on the Parent.

What is actually happening?

App updated caused by a child component when having console logging the computed data

@TDSkyz
Copy link

TDSkyz commented Nov 10, 2018

I found the problem on this.childProp. Anything that affects this variable will trigger the updated. So I define a variable containing the value of childProp on Data line #24, and it solve the problem.

https://jsfiddle.net/je3odvk8/6/

@jackylam1985
Copy link
Author

Thanks @TDSkyz, hmm, but this still does not make sense to me. Why calling the computed function in mounted will cause the app to be updated?

ysj16 pushed a commit to ysj16/vue that referenced this issue Nov 20, 2018
@ysj16
Copy link
Contributor

ysj16 commented Nov 20, 2018

In lifecycle.js lines316 , the method 'callHook', disable dep collection when invoking lifecycle hooks by 'pushTarget()', which means the dep collection will be useless in the lifecycle method. The principle of this is that when pushTarget(), the params--watcher is 'undefined', so in the lifecycle method--mounted, Dep.target is 'undefined', which means will not run dep collection.
But I've found a BUG in this method, when invoking computed in mounted,it will pushTarget a lazyWatcher and then popTarget, during the process, it will lose pre Dep.target, which should be 'undefined' and make it to be the renderWatcher, so will run dep collection and collect the child component‘s property by renderWatcher.
#9095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants