diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index 94ed7d5eb..090603386 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -449,7 +449,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo * @param site Site instance. * @return Promise resolved when done. */ - protected async treatHTMLElements(div: HTMLElement, site?: CoreSite): Promise { + protected treatHTMLElements(div: HTMLElement, site?: CoreSite): void { const images = Array.from(div.querySelectorAll('img')); const anchors = Array.from(div.querySelectorAll('a')); const audios = Array.from(div.querySelectorAll('audio')); @@ -560,7 +560,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo promises.push(CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(promise, 5000))); } - await Promise.all(promises); + // Run asynchronous operations in the background to avoid blocking rendering. + Promise.all(promises).catch(error => CoreUtils.logUnhandledError('Error treating format-text elements', error)); } /** diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index b312ce0ad..3bb84933a 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -139,6 +139,16 @@ export class CoreUtilsProvider { return result; } + /** + * Log an unhandled error. + * + * @param message Message to contextualize the error. + * @param error Error to log. + */ + logUnhandledError(message: string, error: unknown): void { + this.logger.error(message, error); + } + /** * Converts an array of objects to an indexed array, using a property of each entry as the key. * Every entry will contain an array of the found objects of the property identifier.