From 21720a510d66bf32038796e4cbe11c521e8b490e Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Fri, 22 Sep 2023 09:50:44 +0500 Subject: [PATCH] editor: cache src of image when loading from network --- packages/editor/src/extensions/image/component.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/extensions/image/component.tsx b/packages/editor/src/extensions/image/component.tsx index 5a0a40c6f..21f78f11b 100644 --- a/packages/editor/src/extensions/image/component.tsx +++ b/packages/editor/src/extensions/image/component.tsx @@ -69,13 +69,14 @@ export function ImageComponent( const [source, setSource] = useState(); const downloadOptions = useToolbarStore((store) => store.downloadOptions); const isReadonly = !editor.current?.isEditable; - + const hasOrSrc = hash || src; useEffect( () => { (async () => { - if (!src && !dataurl && !IMAGE_SOURCE_CACHE[hash]) return; + if (!src && !dataurl && !IMAGE_SOURCE_CACHE[hasOrSrc]) return; try { - if (IMAGE_SOURCE_CACHE[hash]) setSource(IMAGE_SOURCE_CACHE[hash]); + if (IMAGE_SOURCE_CACHE[hasOrSrc]) + setSource(IMAGE_SOURCE_CACHE[hasOrSrc]); else if (dataurl) setSource(await toBlobURL(dataurl)); else if (isDataUrl(src)) setSource(await toBlobURL(src)); else if (canParse(src)) { @@ -101,7 +102,7 @@ export function ImageComponent( [src, dataurl, imageRef, downloadOptions] ); - if (source && hash) IMAGE_SOURCE_CACHE[hash] = source; + if (source && hasOrSrc) IMAGE_SOURCE_CACHE[hasOrSrc] = source; const relativeHeight = aspectRatio ? editor.view.dom.clientWidth / aspectRatio : undefined;