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

onUnmounted called in keep-alive components #178

Closed
doncatnip opened this issue Nov 4, 2019 · 4 comments · Fixed by #217
Closed

onUnmounted called in keep-alive components #178

doncatnip opened this issue Nov 4, 2019 · 4 comments · Fixed by #217
Labels
bug Something isn't working has PR

Comments

@doncatnip
Copy link

doncatnip commented Nov 4, 2019

When using keep-alive there does not seem to be a way to trigger something on destroyed. onUnmounted gets called every time I navigate away from that component, even though the component persists due to keep-alive. onDestroyed does not exist in the composition API. An oversight ?
(edit) It is a nested component within other tabs that do not have keep-alive. I assumed in this case nested childs will get destroyed when navigating away from the parent component. I guess that isn't the case and so there is no need for an onDestroyed.

@doncatnip
Copy link
Author

Reopening because after a bit of testing there really seems to be a lifecycle hook missing for this case. onUnmounted does not suffice. There need to be a hook that is called once the component is destroyed.

@doncatnip doncatnip reopened this Nov 4, 2019
@LinusBorg
Copy link
Member

The issue seems to be this line:

export const onUnmounted = createLifeCycles(['destroyed', 'deactivated'], genName('unmounted'));

Where the hook of onUnmounted is applied to both the destroyed and deactivated hooks.

This was appearantly done on purpose by @liximomo "to increase compatibility with the rfc" (according to the commit message from the blame for that line), but it could be that this is no longer accurate, not sure from the top of my head.

@doncatnip
Copy link
Author

doncatnip commented Nov 5, 2019

https://vue-composition-api-rfc.netlify.com/api.html#lifecycle-hooks states:
destroyed -> onUnmounted
There is not much else to be found on this topic. If this is in accordance to the RFC, then the RFC should be revisited as destroyed and deactivated have two distinct use cases and should not be merged.

@LinusBorg
Copy link
Member

Yeah I'd rate this a bug. The options API doesn't have a similar API, and there's nothing about deactivated in the RFC.

@LinusBorg LinusBorg added the bug Something isn't working label Dec 19, 2019
@LinusBorg LinusBorg self-assigned this Dec 19, 2019
LinusBorg added a commit that referenced this issue Dec 28, 2019
on unmounted lifecycle

close #178
@LinusBorg LinusBorg removed their assignment Jan 24, 2020
pikax pushed a commit to pikax/vue-function-api that referenced this issue Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants