-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
@click would trigger event other vnode @click event. #6566
Comments
Your repro is working as intended... |
@Kingwl @yyx990803 Sorry about that. I test others case and forgot to change back. The important code is <div class="header" v-if="expand"> // block 1
<i @click="expand = false, countA++">Expand is True</i> // element 1
</div>
<div class="expand" v-if="!expand" @click="expand = true, countB++"> // block 2
<i>Expand is False</i> // element 2
</div> There is four case:
|
So, this happens because:
This is quite tricky in fix, and other libs that leverages microtask for update queueing also have this problem (e.g. Preact). React doesn't seem to have this problem because they use a synthetic event system (probably due to edge cases like this). To work around it, you can simply give the two outer divs different keys to force them to be replaced during updates. This would prevent the bubbled event to be picked up: <div class="header" v-if="expand" key="1"> // block 1
<i @click="expand = false, countA++">Expand is True</i> // element 1
</div>
<div class="expand" v-if="!expand" @click="expand = true, countB++" key="2"> // block 2
<i>Expand is False</i> // element 2
</div> |
This also fixes async edge case #6566 where events propagate too slow and incorrectly trigger handlers post-patch.
This also fixes async edge case vuejs#6566 where events propagate too slow and incorrectly trigger handlers post-patch.
Version
2.4.2
Reproduction link
https://jsbin.com/qejofexedo/edit?html,js,output
Steps to reproduce
see reproduction link.
What is expected?
When I click
Expand is True
, thenexpand
to becomefalse
. And onlycountA
changed.What is actually happening?
When I click
Expand is Ture
, nothing happened.The
countA
andcountB
changed.I guess when I click,
expand
changed tofalse
, but immediate the click event triggered. It executes another vnode click event. Then expand changed totrue
.And More
p
,section
, no errors occur.i
tag to parentdiv
tag in the first div, no errors occurThe text was updated successfully, but these errors were encountered: