Event listener called multiple times with 'once' modifier #1386
Unanswered
kazkansouh
asked this question in
5. Bugs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I noticed that even with marking an event listener with the
.oncemodifier it was still possible for the event handler to be called twice.I believe the issue is in the following:
alpine/src/directives/on.js
Lines 65 to 77 in b0a482f
Here, after the first time an event listener is called, the thread will yields during the
returnValue.then(value => {.... During this time, its possible the event handler to be called again. Maybe the.oncecheck should be performed before the thread yields? Or even set during theaddEventListenercall.Some more specifics
I detected with the following (partial) example:
Note in the above, this is directing all bubbled events to the initial target which is not a correct but it demonstrates the issue.
Then on an Alpine managed object:
This uses a nested
divwith thecollapseclass, so the event will be fired twice due to the selector on the above event listener.Then expanding the nested
divto raise the event will cause the issue. e.g. something like (not tested):$('#x').collapse('show'). This quickly raise two events, which on my Chrome browser results in the event handlerexpandedbeing called twice.Beta Was this translation helpful? Give feedback.
All reactions