wko27 / react-mathjax

MathJax as React component
MIT License
168 stars 71 forks source link

PreProcess isn't always applied correctly #1

Closed wko27 closed 6 years ago

wko27 commented 6 years ago

Just filing this so potential users are aware ... I'm still working on debugging exactly what's going on here.

The issue is if you use a Text node to wrap text in delimiters specified in the options configuration, e.g.:

<Text text="$$x * y$$">
asciimath2jax: {
              useMathMLspacing: true,
              delimiters: [["$$","$$"]],
              preview: "none",
            }

For some reason, the call to PreProcess and Typeset do not always execute correctly and the text remains unchanged. I believe this is because MathJax performs DOM manipulation in its own Queue structure and we're hitting some sort of race condition where it's operating on elements that React has removed.

This is a bit tricky to debug, but various fixes/workarounds I've tried include:

I'll be reaching out to the MathJax developers, but it looks like their primary use case is static webpages.

I've also tried figuring out exactly what's going on in MathJax land, but the intermingling of DOM manipulation code with parsing the asciimath syntax seems pretty convoluted in the v2 source code (see here)

wko27 commented 6 years ago

Yay, fixed this by using Typeset directly. Looks like the PreProcess call was unnecessary and causing the issues.