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

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

Closed
lifetimesw opened this issue Mar 17, 2023 · 7 comments · May be fixed by #8161

Comments

@lifetimesw
Copy link

Vue version

3.2.45

Link to minimal reproduction

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

Steps to reproduce

  • Create a vue3 repo with vue-router
  • Use Composition Api in the components of RouterView
  • Use v-for + ref attribute on the html element
  • Define a proxy object to the ref attribute
  • Change and save the content in <script setup> to trigger hot module replacement

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

@LinusBorg LinusBorg changed the title [bug] Lifecycle hooks has been called twice when I use "v-for + ref" and "script setup" in RouterView. [bug] Lifecycle hooks has been called twice in HMR when I use "v-for + ref" and "script setup" in RouterView. Mar 17, 2023
@toomsie
Copy link

toomsie commented Mar 17, 2023

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

@toomsie
Copy link

toomsie commented Mar 17, 2023

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
Copy link

toomsie commented Mar 17, 2023

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
Copy link

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
Copy link

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

@tuhinjamal
Copy link

I'm facing this issue for each function call .

@edison1105
Copy link
Member

The issue can no longer be reproduced using the latest version of Vue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants