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

dynamicChildren are unmounted multiple times in some cases #2288

Closed
basvanmeurs opened this issue Oct 1, 2020 · 1 comment
Closed

dynamicChildren are unmounted multiple times in some cases #2288

basvanmeurs opened this issue Oct 1, 2020 · 1 comment
Labels
🐞 bug Something isn't working

Comments

@basvanmeurs
Copy link
Contributor

Version

3.0.0

Reproduction link

https://codepen.io/basvanmeurs/pen/xxVoYVE?editors=1111

Steps to reproduce

Just run and view the console log

What is expected?

"MyTest umounted" is shown once

What is actually happening?

"MyTest umounted" is shown twice


I encountered this one when I had a onBeforeUnmounted hook that couldn't handle being run twice. Then after debugging I found that it was run even 4 times.

Digging further I found out that this only happened in case of a component, wrapped into a parent div that has at least one (dynamic) property that references a setup var.

Digging even further I found that what happens is, that when a setup var is being used the patchFlag for that vnode is set to 8. When that happens, it gets added to the dynamicChildren of the encapsulating block, together with the vnode for my-test.

Then later, when unmounting, the code ends up here:
https://github.com/vuejs/vue-next/blob/1abcb2cf61ec16807cae11cfe56acefab19487a1/packages/runtime-core/src/renderer.ts#L2029

First the vnode for my-tests gets unmounted, calling onBeforeUnmounted in the process. Then, next, the wrapper div is also unmounted. But because it also has the my-tests vnode as a child, that is unmounted again later, resulting in another onBeforeUnmounted invocation.

Notice that the component isn't patched double because of the 'optimized' arg that's passed to the patcher which refrains it from patching its children. Maybe a similar approach can be used to prevent double unmounting of dynamicChildren.

@posva posva added the 🐞 bug Something isn't working label Oct 2, 2020
@HcySunYang
Copy link
Member

This is a duplicate of #2169

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants