soscripted / sox

Stack Overflow Extras: a userscript for the Stack Exchange websites to add a bunch of optional toggle-able features
http://stackapps.com/q/6091/
MIT License
72 stars 15 forks source link

AJAX listeners may be run multiple times for the same event #504

Closed yut23 closed 1 year ago

yut23 commented 1 year ago

Describe the bug sox.helpers.addAjaxListener calls sox.helpers.runAjaxHooks, which wraps and replaces XMLHttpRequest.prototype.open. This works fine the first time runAjaxHooks is called, but upon following calls, it re-wraps itself recursively. Each time this happens, all the listeners will be run one more time when triggered. I first noticed this when tag wiki links started getting duplicated in the tag mouseover popup.

To reproduce

  1. Enable Appearance-showTagWikiLinkOnTagPopup and another feature that uses an AJAX listener on a question page (e.g. Appearance-dragBounty, Appearance-standOutDupeCloseMigrated)
  2. Go to a question
  3. Mouse over a tag
  4. See multiple tag wiki links (N = number of addAjaxListener calls)

Expected behaviour runAjaxHooks should remember if it's been run before, and do nothing if so.

Screenshots/GIFs multiple tag wiki links recursive stack trace in devtools

Environment Chrome 111.0.5563.146, SOX 2.8.4 DEV, Tampermonkey

shu8 commented 1 year ago

Thanks for the bug report, and for the detailed investigation!

I'm a bit busy at the moment but will get this fixed as soon as I can!

shu8 commented 1 year ago

This should now be fixed in dev 2.8.6 -- thanks again for the detailed investigation! :)