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

Event fired twice ** although no emit used in code ** #4859

Closed
osasson opened this issue Oct 26, 2021 · 2 comments · Fixed by #4912
Closed

Event fired twice ** although no emit used in code ** #4859

osasson opened this issue Oct 26, 2021 · 2 comments · Fixed by #4912
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. 🐞 bug Something isn't working

Comments

@osasson
Copy link

osasson commented Oct 26, 2021

Version

3.2.19

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Click on the labels in the reproduction

What is expected?

Event should fire only once

What is actually happening?

Event is fired twice


When merging the templates into one template, the fire 2 text fires only once :-)

@LinusBorg LinusBorg added 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. 🐞 bug Something isn't working labels Oct 26, 2021
@LinusBorg
Copy link
Member

LinusBorg commented Oct 26, 2021

This is caused by two things:

  1. You needlessly binding $attrs to the root element, as Vue will do that on its own already (called "attribute fallthrough") and have an additional single @click listener defined.
  2. A failure on Vue's part to detect that the same click event will be added twice when merging attrs in this fallthrough behavior. This only happens in this specific scenario where you already have two click events (which are combined in an array), and then Vue adds fallthrough events on its own.

To be precise, this line doesn't account for event arrays:

https://github.com/vuejs/vue-next/blob/ebd0baca98b618945fba223b94833c2b34cdf6a2/packages/runtime-core/src/vnode.ts#L794

Solution/Workaround for OP:

Either remove v-bind="$attrs" as it's not needed to assign attrs to the root element, or properly add the inheritAttrs: false option if you want to assign $attrs manually.

We still should fix this thoug, as this incomplete check in mergerProps could potentially affect other scenarios as well I would assume.

@soulsam480
Copy link

just discovered this issue where the handler is getting fired two time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants