[fix] Image EncodingError for SVG in Safari iOS 11

Fixes an EncodingError exception being thrown in Safari iOS 11 when
decoding an SVG URL. The exception prevents the onLoad handler from
being called.

Close #1063
This commit is contained in:
Marcel Miranda Ackerman
2018-08-06 15:56:24 +02:00
committed by Nicolas Gallagher
parent 744aaa26d4
commit b9172ceb8e

View File

@@ -52,12 +52,14 @@ const ImageLoader = {
image.onerror = onError;
image.onload = e => {
// avoid blocking the main thread
const onDecode = () => onLoad(e);
if (typeof image.decode === 'function') {
image.decode().then(() => { onLoad(e) });
// Safari currently throws exceptions when decoding svgs.
// We want to catch that error and allow the load handler
// to be forwarded to the onLoad handler in this case
image.decode().then(onDecode, onDecode);
} else {
setTimeout(() => {
onLoad(e);
}, 0);
setTimeout(onDecode, 0);
}
};
image.src = uri;