I can't give steps to reproduce since I haven't released this to production yet, but what I do locally is:
- Create more than one instance of WikiEditor with CodeMirror
- Toggle CodeMirror in one of the instances on and off
Screen recording:
Apart from multiplying search buttons in WikiEditor, after several such togglings Chrome freezes and I see in DevTools that the execution gets stuck on the line https://github.com/wikimedia/mediawiki-extensions-CodeMirror/blame/6311920da97bbce7e849fda605811944a673d92c/resources/codemirror.wikieditor.js#L225:
// Restore original search button. this.$searchBtn.replaceWith( this.$oldSearchBtn );
where it cycles in a really long loop.
The cause seems to be the fact that an absolute selector is used on the line https://github.com/wikimedia/mediawiki-extensions-CodeMirror/blame/6311920da97bbce7e849fda605811944a673d92c/resources/codemirror.wikieditor.js#L188
this.$searchBtn = $( '.wikiEditor-ui .group-search .tool' );
instead of a relative one (like this.$textarea.closest('.wikiEditor-ui').find('.group-search .tool')). It can collect more than one search button from the page which will then lead to said issues.
Please tell me If this information is not enough.
