Skip to content

Commit 341d1bc

Browse files
committed
MOBILE-4672 mathjax: Fix some equations not displayed in quiz
For some reason, if we tell MathJax to render an equation for an element that isn't in the DOM, for some equations it fails and displays the error message (which is an exclamation mark). If we want to be sure the equation is rendered properly we need to wait for the element to be in the DOM.
1 parent 325aca7 commit 341d1bc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { CoreEvents } from '@singletons/events';
2424
import { CoreSite } from '@classes/sites/site';
2525
import { makeSingleton } from '@singletons';
2626
import { CoreWait } from '@singletons/wait';
27+
import { CoreDom } from '@singletons/dom';
2728

2829
/**
2930
* Handler to support the MathJax filter.
@@ -177,6 +178,10 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
177178
): Promise<void> {
178179
await this.waitForReady();
179180

181+
// Make sure the element is in DOM, otherwise some equations don't work.
182+
// Automatically timeout the promise after a certain time, we don't want to wait forever.
183+
await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(CoreDom.waitToBeInDOM(container), 15000));
184+
180185
await this.window.M!.filter_mathjaxloader!.typeset(container);
181186
}
182187

0 commit comments

Comments
 (0)