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

Vue.$destroy(remove) does not trigger "detached" hook on second level children #1966

Closed
tgeorgiev opened this issue Dec 4, 2015 · 2 comments

Comments

@tgeorgiev
Copy link

I have experienced this issue where I have 3 levels of Vue components, calling $destroy on the top most component will not trigger the detached hook on the bottom most child.

By looking at the _destroy function, I think that the issue is that $remove is called last and at this point, on children in the hierarchy $destroy was called, causing them to remove event hooks ($off() as part of _cleanup).

I think that the removal should be brought before those cleanups, and the lifecycle order should be changed.
Evan, please excuse me if I breaking something or making faulty statement, but I couldn't anywhere when the detached hook is supposed to be called. I found one test that validates that is called after destroyed, but in my humble opinion I think that detached should be called before destroyed. After all shouldn't there be a state for a component from detached, to go back to attached, before we have destroyed the instance?

What I mean to say is that having such component hierarchy
A
-B
--C

when calling A.$destroy, the events would be
detached
-detached
--detached
beforeDestroy
-beforeDestroy
--beforeDestroy
--destroyed
-destroyed
destroyed

You can observe it here http://jsfiddle.net/pepbu9cf/

I have a pending proposal for fix, will post soon.

@tgeorgiev
Copy link
Author

A possible workarround that I tried and works for me is instead of

vue.$destroy(true)

to call

vue.$remove(function() {
  vue.$destroy();
});

tgeorgiev added a commit to tgeorgiev/vue that referenced this issue Dec 4, 2015
…d level children

Please see issue for description about the problem and what this change is supposed to fix - vuejs#1966
I know that it doesn't look good to modify tests when they fail because of a change, but I think that the lifecycle hook order should be different than what the existing test validates. The problem is again described in the issue summary
@yyx990803
Copy link
Member

Merged #1967

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

No branches or pull requests

2 participants