8
$\begingroup$

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).

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Martin Sleziak Mar 30 at 6:28
  • $\begingroup$ @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. $\endgroup$ – Bill Dubuque Mar 30 at 13:01
4
$\begingroup$

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(() => {
    Editor.creationCallbacks.add((editor) => {
        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.

Open questions include a hidden answer editor that instantly triggers the editor features to download, but doesn't try configuring itself until you click "Add an answer". "Ask a question" probably had a similar condition I didn't expect.

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.

How was this fixed?

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

var loaded = false;
var loadCallbacks = $.Callbacks();

Editor.creationCallbacks.add((editor) => {
    if (loaded) {
        configureEditorWithMathJaxFeatures(editor);
    } else {
        loadCallbacks.add(() => {
            configureEditorWithMathJaxFeatures(editor);
            refreshEditorPreview(editor);
        });
    }
});

loadMathJaxEditorFeatures()
.done(() => {
    loaded = true;
    loadCallbacks.fire();
    loadCallbacks.empty();
});

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Lee David Chung Lin Apr 12 at 18:05
  • $\begingroup$ @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. $\endgroup$ – Brian Nickel Apr 12 at 18:09
  • $\begingroup$ Seems to do the trick. Thanks very much. $\endgroup$ – Bill Dubuque Apr 13 at 2:08
  • $\begingroup$ @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? $\endgroup$ – Bill Dubuque May 7 at 15:34
  • $\begingroup$ @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? $\endgroup$ – Brian Nickel May 7 at 17:25
  • $\begingroup$ @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. $\endgroup$ – Bill Dubuque May 7 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .