vuejs / core

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

[bug] Lifecycle hooks has been called twice in HMR when I use "v-for + ref" and "script setup" in RouterView. #7908

Open lifetimesw opened 1 year ago

lifetimesw commented 1 year ago

Vue version

3.2.45

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-fx7e3m?file=src/views/HelloWorld.vue

Steps to reproduce

What is expected?

onMounted will be Called once

What is actually happening?

onMounted will be Called twice.

System Info

"mounted" will be print twice on the browser console

Any additional comments?

动画 1679047586712

toomsie commented 1 year ago

Thanks very much, it took me a while to before I checked the chrome dev tools.

toomsie commented 1 year ago

I did simplify the code by removing line 12: <p v-for="(x, i) in 10" :key="i" ref="pRefs">{{ x }}</p>. but still the same thing happens. 🙁

toomsie commented 1 year ago

Fix the problem. I believe that setup(){} function helped somewhat. The setup function is only executed only one in vue.js 3, if I am correct.

https://stackblitz.com/edit/vitejs-vite-nzzz5i?file=src%2Fviews%2FHelloWorld.vue

jinusean commented 1 year ago

I am facing this issue even without v-for. I have a ref to a custom component whose onMounted function is being called twice

benjaminrobinet commented 11 months ago

Upvote this issue, I still reproduce using latest Vue version.

tuhinjamal commented 4 months ago

I'm facing this issue for each function call .