vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.7k stars 8.33k forks source link

hook onMounted has been called when app unmount #11037

Open kkagura opened 5 months ago

kkagura commented 5 months ago

Vue version

3.4.21

Link to minimal reproduction

https://github.com/kkagura/test-unmount

Steps to reproduce

  1. open /page1 and click the button to go to /page2
  2. click button to unmount app

What is expected?

hook onMounted in Page2.vue should not be called when app unmount

What is actually happening?

hook onMounted has been called when app unmount

System Info

System:
    OS: macOS 12.2.1
    CPU: (8) arm64 Apple M1
    Memory: 73.73 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
    pnpm: 7.11.0 - ~/.nvm/versions/node/v16.17.0/bin/pnpm
  Browsers:
    Chrome: 125.0.6422.78
    Safari: 15.3
  npmPackages:
    vue: ^3.4.21 => 3.4.27

Any additional comments?

No response

yangliguo7 commented 5 months ago

https://github.com/kkagura/test-unmount/blob/7d8e091fc7215bdd020dbd1df1197f88a8630aa3/src/views/Page2.vue#L8-L10

use mode out-in will trigger mount effect when use unmount. the mount effect will be added to effetc quene

https://github.com/vuejs/core/blob/main/packages/runtime-core/src/components/Suspense.ts#L544-L554

maybe this is indeed a bug .