2
votes

I've encountered an issue with ember's (app is on 2.6.0, but seems to happen in latest as well) rendering process and its compatibility with the MathJax.js library. I have an ember twiddle (linked below) that isolates the problem, but essentially it seems like MathJax's rendering of inline equations that occur in the middle of a single text node breaks ember's re-rendering, in that the single text node becomes multiple text nodes after MathJax transforms the inline equation text into its Math elements, and the 2nd text node becomes orphaned, and remains in the DOM across re-renders.

https://ember-twiddle.com/cadfb80d7c90df98353cc3d9900f2b73/1ab7f66c3c6ca4aad15bf443bbe02fbb1f79a0d4?openFiles=controllers.application.js%2C

It may just be that my integration of mathjax with ember is just not correct, so I'd love some pointers if thats the case.

1
Could you describe in more detail what the desired behavior (vs the existing behavior) of your twiddle is? It seems to be working as expected for me (but I'm no ember expert.) - Peter Krautzberger
@PeterKrautzberger sorry, forgot to update this. I eventually solved the issue in the linked twiddle (see my answer below), which is why it was working. I updated the original question w/a link to the twiddle at the revision where the issue was still occuring. - Bill Dami
Ah, thanks for the follow up. Good to see you could resolve the issue. - Peter Krautzberger

1 Answers

1
votes

I was able to fix this with a somewhat hacky workaround:

https://ember-twiddle.com/cadfb80d7c90df98353cc3d9900f2b73

The issue (as confirmed on slack by some ember core team members) is with how MathJax modifies the DOM, in that ember is not able to keep track of the extra nodes it creates, and as a result can not properly clean up after it on re-renders.

To solve this, the component which contains the mathjax content manually sets its element's innerHTML to whatever the content attribute is set to when didRender() is fired, effectively wiping out all the DOM created/modified by MathJax. MathJax's rendering process is then invoked to render any formulas in the newly rendered content.

Note that if your content does not contain any HTML, it is recommended to set element.innerText instead of element.innerHTML.