SamyPesse / react-mathjax

React component to display math formulas
Apache License 2.0
95 stars 35 forks source link

MathJax.Provider doesn't load MathJax when the first node is added after componentDidMount. #23

Open bigblind opened 5 years ago

bigblind commented 5 years ago

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.

StefanSmith commented 5 years ago

Hit the same problem. Currently working around it with the following:

class EagerMathJaxProvider extends MathJax.Provider {
    componentDidMount() {
        this.state.registerNode();
        super.componentDidMount && super.componentDidMount();
    }
}
iroy2000 commented 4 years ago

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

Screen Shot 2020-01-13 at 5 38 02 PM

Any advice will be appreciated.

iroy2000 commented 4 years ago

My problem is solved by switching to https://github.com/wko27/react-mathjax