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

onBeforeMount and onMount called, but onBeforeUnmount and onUnmount not, if inside <transition> #6260

Closed
plehnen opened this issue Jul 12, 2022 · 4 comments

Comments

@plehnen
Copy link

plehnen commented Jul 12, 2022

Vue version

3.2.27

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-5pepm1?file=src/components/Page1.vue

Steps to reproduce

If component A is itself loading a child component inside a <transition>, but A is replaced by B during loading, the child component is only executing the onBeforeMount and onMount hook, but not the Unmount hooks, even though it is removed from the DOM and not visible anymore.

This issue only happens if the timing is right. In our project (with vue cli and a lot of stuff) I could reproduce it with a promise of 10ms, and a page transition after 100ms. But in the reproduction link it behaved differently. There it only executes the onBeforeMount and not the onMount, and I see an error which I don't get locally in our project.

What is expected?

onBeforeUnmount and onUnmounted should be called consistently and reliably!

What is actually happening?

Sometimes only the onBeforeMount and onMounted hooks are executed, and not the unmount hooks, even though the component gets destroyed by routing to a different page.

System Info

Windows 10, latest Chrome

Any additional comments?

No response

@plehnen
Copy link
Author

plehnen commented Jul 13, 2022

The thing is, in our project this inner component uses Teleport. Sometimes the backend sends an error and vue router redirects to the error page - this redirect happens while the Transition is running, and the inner component is mounted but never removed. So all states are still active, including the Teleport content.
So I can't even work around this issue by resetting the state, since the Teleport is still showing content which doesn't belong there, as the current route is already a different one and it should have been removed.

@plehnen
Copy link
Author

plehnen commented Jul 14, 2022

Seems like the following edge-case causes troubles:

  • Component is loaded inside "leave-transition" which is transitioning away from it (so it is removing the component after transition)
  • inner component executes onBeforeMount and onMounted hooks
  • inner component is technically removed, but still existing since it was detached from the DOM inside a transition
  • component is still loaded and active. onUnmount is never called and component is never destroyed, even though it is not attached to the DOM anymore and should have been removed
  • any teleport content within the inner component is still visible

@ml1nk
Copy link

ml1nk commented Oct 21, 2022

Same problem here on the current version 3.2.41. Is it related to #6347 and hopefully fixed with #6529?

@edison1105
Copy link
Member

Closing as it can not reproduce anymore with the latest version.
Maybe fixed via #9370

@edison1105 edison1105 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants