react-mathjax
react-mathjax copied to clipboard
MathJax.Provider doesn't load MathJax when the first node is added after componentDidMount.
MathJax.Provider calls this.load() only in componentDidMount and componentDidUpdate.
load() then loads Mathax if this.hasNodes is true, which in turn is set when a node calls the registerNode function it receives from the context. The hasNodes is stored on the Mathax.Provider instance itself, rather than the state, so setting it doesn't cause componentDidUpdate to be called, so at least one component needs to be registered before componentDidMount is called.
So I propose making hasNodes part of the state, and will submit a PR to do just that. Let me know if I'm misunderstanding anything.
Hit the same problem. Currently working around it with the following:
class EagerMathJaxProvider extends MathJax.Provider {
componentDidMount() {
this.state.registerNode();
super.componentDidMount && super.componentDidMount();
}
}
Thanks for the solution. @StefanSmith
I tried that solution, and because I have a paginated page, and if I paginate fast enough, the math formula occasionally won't render correctly.
For example, I will see the following

Any advice will be appreciated.
My problem is solved by switching to https://github.com/wko27/react-mathjax