Mousetrap.js doesn’t properly stop callbacks for events originating from a shadow DOM


(Philipp Rudloff) #1

I’m experimenting with shadow DOM in a Discourse plugin I’m writing and noticed that mousetrap.js is not stopping callbacks for events that originate in the shadow DOM. For example, pressing u in an input element triggers the Discourse shortcut for history back navigation; thus, stopping me from filling out any forms.

I’m mainly adding this as a reference for people running into this in the future because it’s unlikely this can be fixed in Discourse without replacing mousetrap.js (except for monkey-patching the file).


(Gerhard Schlager) #2

It would be great if you could get this fixed upstream. That would make our lives a lot easier, because we use yarn for that dependency and we’d like to avoid monkey patching. Please feel free to ping us or create a PR to update our dependency when a new version with the fix has been released.


(Philipp Rudloff) #3

I asked whether they want a new pull request because I don’t want to just hijack the existing pull request although it is stale for three years. We’ll see.


(Philipp Rudloff) #4

I submitted a pull request upstream: Shadow DOM: Stop callbacks from inside an open shadow tree by kleinfreund · Pull Request #438 · ccampbell/mousetrap · GitHub


(Gerhard Schlager) #5

Oh, I just noticed that we are using a fork of mousetrap because we had to apply a patch that hasn’t been merged yet. :see_no_evil:

So, yeah, I guess you could send the pull request to our fork if there’s no reaction in the upstream project in a reasonable timeframe.


(Philipp Rudloff) #6

@gerhard Hey. So far there hasn’t been a reaction to the pull request. Could you (or someone else) update the fork to include the latest changes (a merged pull request I did before to update development dependencies) so that I can submit a pull request to the fork based on that state?