Przeglądaj źródła

WIP: render page with react component

fix renderMathJax when renderMathJaxOnInit is true
Yuki Takei 8 lat temu
rodzic
commit
ae55c20331
1 zmienionych plików z 9 dodań i 7 usunięć
  1. 9 7
      resource/js/components/Page/RevisionBody.js

+ 9 - 7
resource/js/components/Page/RevisionBody.js

@@ -8,22 +8,24 @@ export default class RevisionBody extends React.Component {
   }
 
   componentDidMount() {
-    if (this.props.isMathJaxEnabled && this.props.renderMathJaxOnInit) {
-      this.renderMathJax();
+    if (MathJax != null && this.props.isMathJaxEnabled && this.props.renderMathJaxOnInit) {
+      const intervalId = setInterval(() => {
+        if (MathJax.isReady) {
+          this.renderMathJax();
+          clearInterval(intervalId);
+        }
+      }, 100);
     }
   }
 
   componentDidUpdate() {
-    if (this.props.isMathJaxEnabled && this.props.renderMathJaxInRealtime) {
+    if (MathJax != null && this.props.isMathJaxEnabled && this.props.renderMathJaxInRealtime) {
       this.renderMathJax();
     }
   }
 
   renderMathJax() {
-    const MathJax = window.MathJax;
-    if (MathJax != null) {
-      MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.element]);
-    }
+    MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.element]);
   }
 
   generateInnerHtml(html) {