@@ -40,7 +40,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
4040 /**
4141 * Initialize MathJax.
4242 */
43- async initialize ( ) : Promise < void > {
43+ initialize ( ) : void {
4444 if ( document . head . querySelector ( '#core-filter-mathjax-script' ) ) {
4545 // Script already added, don't add it again.
4646 return ;
@@ -111,8 +111,6 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
111111 * @inheritdoc
112112 */
113113 async handleHtml ( container : HTMLElement ) : Promise < void > {
114- await this . waitForReady ( ) ;
115-
116114 // Make sure the element is in DOM, otherwise some equations don't work.
117115 // Automatically timeout the promise after a certain time, we don't want to wait forever.
118116 await CorePromiseUtils . ignoreErrors ( CorePromiseUtils . timeoutPromise ( CoreDom . waitToBeInDOM ( container ) , 15000 ) ) ;
@@ -150,6 +148,12 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
150148 */
151149 protected async typeset ( container : HTMLElement ) : Promise < void > {
152150 const equations = Array . from ( container . getElementsByClassName ( 'filter_mathjaxloader_equation' ) ) ;
151+ if ( ! equations . length ) {
152+ return ;
153+ }
154+
155+ this . initialize ( ) ;
156+ await this . waitForReady ( ) ;
153157
154158 await Promise . all ( equations . map ( ( node ) => this . typesetNode ( node ) ) ) ;
155159 }
@@ -186,12 +190,12 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
186190 * @returns Promise resolved when ready or if it took too long to load.
187191 */
188192 protected async waitForReady ( retries : number = 0 ) : Promise < void > {
189- if ( this . window . MathJax ?. typesetPromise || retries >= 20 ) {
193+ if ( this . window . MathJax ?. typesetPromise || retries >= 25 ) {
190194 // Loaded or too many retries, stop.
191195 return ;
192196 }
193197
194- await CoreWait . wait ( 250 ) ;
198+ await CoreWait . wait ( 20 + 10 * retries ) ;
195199 await CorePromiseUtils . ignoreErrors ( this . waitForReady ( retries + 1 ) ) ;
196200 }
197201
0 commit comments