From 175fa1606cd05e9c130c11ad353d84e65576ed46 Mon Sep 17 00:00:00 2001 From: tomdyqin Date: Fri, 16 Jun 2023 14:34:45 +0800 Subject: [PATCH] fix(@hippy/react-web): fix Image repeatedly triggering onError --- packages/hippy-react-web/src/components/image.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/hippy-react-web/src/components/image.tsx b/packages/hippy-react-web/src/components/image.tsx index 48f107a17b4..ab4b0d109b2 100644 --- a/packages/hippy-react-web/src/components/image.tsx +++ b/packages/hippy-react-web/src/components/image.tsx @@ -131,6 +131,7 @@ const Image: React.FC = React.forwardRef((props: ImageProps, ref) => useElementLayout(imgRef, onLayout); const [imgSource, setImgSource] = useState(defaultSource ? { uri: defaultSource } : source); + const [loadedSource, setLoadedSource] = useState(''); const onImageLoad = () => { if (onLoad && isFunc(onLoad)) { @@ -154,10 +155,11 @@ const Image: React.FC = React.forwardRef((props: ImageProps, ref) => }); } onLoadEnd(); + setLoadedSource(source.uri); }; - // load source url when provide defaultSource - if (imgSource.uri !== source.uri) { + // first load source url when provide defaultSource + if (imgSource.uri !== source.uri && loadedSource !== source.uri) { ImageLoader.load(source.uri, () => { setImgSource(source); onImageLoad();