From 341d1bc6d4d1811c497c1d69fccb0b231ccb78d3 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 7 Oct 2024 16:16:10 +0200 Subject: [PATCH] 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. --- .../filter/mathjaxloader/services/handlers/mathjaxloader.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index 9728707e1..0ad77d343 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -24,6 +24,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreSite } from '@classes/sites/site'; import { makeSingleton } from '@singletons'; import { CoreWait } from '@singletons/wait'; +import { CoreDom } from '@singletons/dom'; /** * Handler to support the MathJax filter. @@ -177,6 +178,10 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan ): Promise { await this.waitForReady(); + // Make sure the element is in DOM, otherwise some equations don't work. + // Automatically timeout the promise after a certain time, we don't want to wait forever. + await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(CoreDom.waitToBeInDOM(container), 15000)); + await this.window.M!.filter_mathjaxloader!.typeset(container); }