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});
return value;
},
// $FlowFixMe - get/set properties not yet supported
get SUPPORT_SVG_DRAWING() {
'use strict';
const value = testSVG(document);

View File

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