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

onBeforeUnmount not invoked for specific dynamicChildren-optimized case #2444

Closed
basvanmeurs opened this issue Oct 20, 2020 · 4 comments · Fixed by #2445
Closed

onBeforeUnmount not invoked for specific dynamicChildren-optimized case #2444

basvanmeurs opened this issue Oct 20, 2020 · 4 comments · Fixed by #2445

Comments

@basvanmeurs
Copy link
Contributor

basvanmeurs commented Oct 20, 2020

Version

3.0.1

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 not shown


This behavior changed from 3.0.0 to 3.0.1.
Probably related to 376883d

@basvanmeurs basvanmeurs reopened this Oct 20, 2020
@basvanmeurs basvanmeurs changed the title onBeforeUnmount not invoked for dynamicChildren onBeforeUnmount not invoked for specific dynamicChildren-optimized case Oct 20, 2020
@posva
Copy link
Member

posva commented Oct 20, 2020

In your repro block.id is always undefined since block is an array. What I found is an error when using:

const MyTest = {
  template: "#my-test",
  setup() {
    Vue.onBeforeUnmount(() => {
      console.log("MyTest umounted")
    });
  }
}  

const App = { 
  components: {
    MyTest
  },
  setup() {
    const block = Vue.shallowRef({id:1});
    setTimeout(() => {
      console.log("this should unmount")
      block.value = null;
    }, 1000);
    return {
      block
    }
  }
}

Vue.createApp(App).mount("#main");

maybe that's what you meant

@unbyte
Copy link
Contributor

unbyte commented Oct 20, 2020

the component was not unmounted at all

<my-test v-for="id in [block.id]" :key="id" /> => <my-test v-for="b in block" :key="b.id" />

@basvanmeurs
Copy link
Contributor Author

Excuse me. I've updated the example

@matthew-dean
Copy link

matthew-dean commented Apr 18, 2023

I think I've run into this same bug on Vue 3.2.47. I have one particular component which has two children, a slot, and a dialog, like:

<template>
  <slot :on-click="onClick"></slot>
  <Dialog {some options} />
</template>

In my <script setup>, I have an onBeforeUnmount and onUnmounted callback. Neither of them ever fires, in any circumstances. Just for this one component. And it's definitely being unmounted. Of note is that the Dialog only mounts content via <Teleport>

I've been trying to create a reproduction on CodeSandbox and I haven't been able to do it. Is there any way to prevent this "optimized" path from taking place?

@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants