From ebd4577be26338b5617fb7062a5cd35396f5a195 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 27 Aug 2019 09:27:13 +0200 Subject: [PATCH] MOBILE-3068 core: Fix img loaded event if no URL --- src/directives/external-content.ts | 16 +++++++++++----- src/directives/format-text.ts | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/directives/external-content.ts b/src/directives/external-content.ts index e70858ab0..4026e7e0a 100644 --- a/src/directives/external-content.ts +++ b/src/directives/external-content.ts @@ -152,12 +152,22 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { // Avoid handling data url's. if (url && url.indexOf('data:') === 0) { this.invalid = true; + this.onLoad.emit(); + this.loaded = true; return; } this.handleExternalContent(targetAttr, url, siteId).catch(() => { - // Ignore errors. + // Error handling content. Make sure the loaded event is triggered for images. + if (tagName === 'IMG') { + if (url) { + this.waitForLoad(); + } else { + this.onLoad.emit(); + this.loaded = true; + } + } }); } @@ -204,10 +214,6 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { this.addSource(url); } - if (tagName === 'IMG') { - this.waitForLoad(); - } - return Promise.reject(null); } diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index e8bafbbab..ede668a6b 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -468,7 +468,8 @@ export class CoreFormatTextDirective implements OnChanges { // Wait for images to load. let promise: Promise = null; if (externalImages.length) { - promise = Promise.all(externalImages.map((externalImage): any => { + // Automatically reject the promise after 5 seconds to prevent blocking the user forever. + promise = this.utils.timeoutPromise(this.utils.allPromises(externalImages.map((externalImage): any => { if (externalImage.loaded) { // Image has already been loaded, no need to wait. return Promise.resolve(); @@ -480,7 +481,7 @@ export class CoreFormatTextDirective implements OnChanges { resolve(); }); }); - })); + })), 5000); } else { promise = Promise.resolve(); }