Fix infinite loop in Content Editor codeblocks
What does this MR do and why?
This MR fixes a bug caused by a conflict of ProseMirror and a MutationObserver object used by the copy_code feature introduced in !75433 (merged). ProseMirror is a rich text editor framework with an architecture that separates DOM from a Document model. ProseMirror has a mechanism that keeps the Document model and DOM in sync. When the copy_code feature introduces a MutationObserver object that mutates the DOM generated by ProseMirror, ProseMirror detects this DOM as stale, and reverts those changes.
In turn, the MutationObserver detects the changes made by ProseMirror, and triggers a new update which causes an infinite loop. This infinite loop causes the web browser to crash.
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
In a local environment, this bug just generates a console error because the copy_code feature assumes that querySelectorAll returns a DOM element with an attr method which is strange. In gitlab.com, the infinite loop crash happens and you can test it by:
- Editing a Wiki page in gitlab.com using the Content Editor.
- Adding a code block in the Classic Markdown Editor and clicking the
Edit rich texttoggle button. - The content editor will never load due to the infinite loop problem.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #349530 (closed)