Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: cache src of image when loading from network

Ammar Ahmed21720a510d66
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<string>();
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;