# MathJax very slow in questions that are closed

MathJax redisplay is very slow in the preview pane while editing answers in closed questions. Redisplay that normally happens in under a second can take up to $$5$$ times longer.

Not too infrequently when organizing dupes I need to edit older closed questions, so I have to resort to performing the edit elsewhere in order to workaround this problem. This is a bit of a pain so it would be nice if it could be fixed (I suspect it is an easy fix).

• Perhaps (markdown-preview) might be a suitable tag here - since this tag is, as far as I can tell, for the questions about the preview. – Martin Sleziak Mar 30 '19 at 6:28
• @MartinSleziak I wan't sure about the scope of that tag when originally tagging it, but on 2nd thought maybe it will help it get the correct exposure. – Bill Dubuque Mar 30 '19 at 13:01

This is fixed.

## What went wrong?

When we insert an editor into a page on a site that includes MathJax, we inject some JavaScript that looked like this:

loadMathJaxEditorFeatures()
.done(() => {
configureEditorWithMathJaxFeatures(editor);
});
});


Basically, this lazy loads the features needed for MathJax and adds those configuration steps when creating a new editor. Unfortunately, this only affects editors created after the feature was loaded, triggering a race between the file download and the editor field initialization.

So, why was this only affecting closed questions? It turns out it wasn't. It happened on any page where an edit field was late loaded (not in the body). E.g., protected questions or review queues.

Also, it only affected the first post on a page you edited, since the configuration callback was set up with the first editor.

## Why was it just slow and not completely broken?

MathJax did eventually render because 5 seconds after you stop typing we trigger styleCode() a function that triggers MathJax rendering and code block syntax highlighting. We do that on all sites with a high delay because syntax highlighting isn't critical during editing.

I moved code around so basically this happens the when we load the editor code:

var loaded = false;

configureEditorWithMathJaxFeatures(editor);
} else {
configureEditorWithMathJaxFeatures(editor);
refreshEditorPreview(editor);
});
}
});

.done(() => {
});


This code keeps track of editors that were configured prior to the features being loaded, applies the features and refreshes the previews.

• There are also some problems with mathjax when editing in the review queue. I don't know if it's the same issues or not. – Lee David Chung Lin Apr 12 '19 at 18:05
• @LeeDavidChungLin The change just went live and should fix this specific issue with MathJax in the review queue. If there are others, let me know. – Brian Nickel Apr 12 '19 at 18:09
• Seems to do the trick. Thanks very much. – Bill Dubuque Apr 13 '19 at 2:08
• @Brian The same bug now seems topccur after an answer is accpeted, e.g. here. Should I post a new bug report or does this comment suffice? – Bill Dubuque May 7 '19 at 15:34
• @BillDubuque I'm not able to reproduce the issue on questions with accepted answers. Editing either the question or the answer results in immediate rendering. Are there specific steps that I should be following? – Brian Nickel May 7 '19 at 17:25
• @Brian There have been some changes (unacceptance) so, alas, it seems no longer to be repro. This is not the first time I've noticed that the bug still happens in some contexts, but it seems like it may be tricky to get a repro instance, sigh. – Bill Dubuque May 7 '19 at 17:30