-
Notifications
You must be signed in to change notification settings - Fork 81
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
Remove doubling proxied event handlers in NcRichContenteditable
#3875
Remove doubling proxied event handlers in NcRichContenteditable
#3875
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit hackish to me?
What about just stopping the propagation and preventing defaults on the @paste
event?
The problem is not about the DOM event but the Vue component custom event handler. <NcRichContenteditable @paste="customEventHandler" /> Then the component adds native DOM event handlers on the div: <div @paste="onPaste" v-on="$listeners" /> Which is "equal" to <div @paste="$emit('paste')" @paste="$listeners.paste()" /> So on the paste:
Maybe 😀. I personally always use this approach on a wrapper-component if I need to patch specific native event handlers while proxying all handlers. It is always a problem if you combine A simple alternative is to remove I'm also okay with removing P.S. This problem was solved in Vue 3. They removed |
@skjnldsv Hi, do you have any thoughts about this solution or an alternative way to solve duplicating native + vue events? |
With the amount of work I've spent on this component to try to mitigate and handle every use case, I'm too afraid to touch it. It's been a while, but I do remember the struggle back then. Sorry, but I don't have time right now to give a proper review and in-depth check 😞 |
Just found that the same approach is described in the Vue 2 documentation: https://v2.vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components The only difference is that in the docs computed does not remove, but replaces listeners. While in this PR computed removes listeners that are replaced in the template. The result is the same, but replacing the listeners in the computed is fine by me either. It allows removing timestamp check on path event handling: https://github.com/nextcloud/spreed/blob/cd0a971a2bdad0c8f5a177e958f0ebe99d33d505/src/components/NewMessage/NewMessage.vue#L596-L603 |
b0dfd3c
to
4baee0c
Compare
Rebased onto master |
Co-authored-by: Pytal <24800714+Pytal@users.noreply.github.com> Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
3752706
to
9bdba1b
Compare
/backport to stable7 |
A problem
All component's event handlers were set as native event handlers with by
v-on="$listeners"
.It allows using event handlers without the
.native
modifier for native events.But the component also raised custom events manually by
$emit
, including corresponding native events. As a result, it triggers such handlers twice.Related issue: nextcloud/spreed#9004
Steps to reproduce
Actual behavior
handler
is called twice:handler
will be called by$emit('paste')
handler
will be called byv-on="$listeners"
.Expected behavior
handler
is called once.Proposed solution
In this PR with the
v-on="listeners"
directive only proxied native event handlers are set, without custom events.Alternative solution
There is a simple alternative solution: remove
this.$emit('paste', event)
fromonPaste
handler. It also removes the doublingpaste
event.I suggest the solution from the PR because:
emits
option) and behavior with conditions inonPaste
.submit
andupdate:value
event handlers are not removed because they don't exist as native events ondiv
.