From b9172ceb8e0779c41e17210e56da36bdcc3e438b Mon Sep 17 00:00:00 2001 From: Marcel Miranda Ackerman Date: Mon, 6 Aug 2018 15:56:24 +0200 Subject: [PATCH] [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 --- .../react-native-web/src/modules/ImageLoader/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react-native-web/src/modules/ImageLoader/index.js b/packages/react-native-web/src/modules/ImageLoader/index.js index ff6f7a16..8fc2f592 100644 --- a/packages/react-native-web/src/modules/ImageLoader/index.js +++ b/packages/react-native-web/src/modules/ImageLoader/index.js @@ -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;