Don't resolve images immediately if they appear complete

This commit is contained in:
Niklas von Hertzen 2017-08-13 13:57:03 +08:00
parent 37a9249a4a
commit f3d6d2fdf4
2 changed files with 7 additions and 6 deletions

View File

@ -48,6 +48,7 @@ const FEATURES = {
Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', {value}); Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', {value});
return value; return value;
}, },
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_SVG_DRAWING() { get SUPPORT_SVG_DRAWING() {
'use strict'; 'use strict';
const value = testSVG(document); const value = testSVG(document);

View File

@ -37,11 +37,7 @@ export default class ImageLoader {
return this.addImage(src, src); return this.addImage(src, src);
} }
} else { } else {
if ( if (this.options.allowTaint === true || isInlineImage(src) || this.isSameOrigin(src)) {
this.options.allowTaint === true ||
isInlineImage(src) ||
this.isSameOrigin(src)
) {
return this.addImage(src, src); return this.addImage(src, src);
} else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) { } else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) {
// TODO proxy // TODO proxy
@ -66,10 +62,14 @@ export default class ImageLoader {
this.cache[key] = new Promise((resolve, reject) => { this.cache[key] = new Promise((resolve, reject) => {
const img = new Image(); const img = new Image();
img.onload = () => resolve(img); img.onload = () => resolve(img);
img.onerror = reject; img.onerror = reject;
img.src = src; img.src = src;
if (img.complete === true) { if (img.complete === true) {
resolve(img); // Inline XML images may fail to parse, throwing an Error later on
setTimeout(() => {
resolve(img);
}, 500);
} }
}); });
return key; return key;