Correctly apply image timeout for loading images

This commit is contained in:
Niklas von Hertzen 2017-08-18 21:53:42 +08:00
parent c093c95881
commit bd463d9343
2 changed files with 12 additions and 3 deletions

View File

@ -78,10 +78,12 @@ export default class ImageLoader<T> {
}
}
};
xhr.ontimeout = () => reject(`Timed out fetching ${src}`);
xhr.responseType = 'blob';
if (this.options.imageTimeout) {
xhr.timeout = this.options.imageTimeout;
const timeout = this.options.imageTimeout;
xhr.timeout = timeout;
xhr.ontimeout = () =>
reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : '');
}
xhr.open('GET', src, true);
xhr.send();
@ -122,6 +124,13 @@ export default class ImageLoader<T> {
resolve(img);
}, 500);
}
if (this.options.imageTimeout) {
const timeout = this.options.imageTimeout;
setTimeout(
() => reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : ''),
timeout
);
}
});
this.cache[key] =

View File

@ -19,7 +19,7 @@ export type Options = {
async: ?boolean,
allowTaint: ?boolean,
canvas: ?HTMLCanvasElement,
imageTimeout: ?number,
imageTimeout: number,
proxy: ?string,
removeContainer: ?boolean,
scale: number,