From a52ef3dc143292d4e7717bcd770948018b259fd8 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 8 Mar 2023 13:14:38 -0800 Subject: [PATCH] cimg: minor improvements --- src/components/frame/XImg.vue | 10 ++++------ src/components/frame/XImgCache.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/frame/XImg.vue b/src/components/frame/XImg.vue index efe3b0b6..49e6be0a 100644 --- a/src/components/frame/XImg.vue +++ b/src/components/frame/XImg.vue @@ -72,20 +72,18 @@ export default defineComponent({ // Check if the blob cache exists if (!usedCache(this.src)) { const src = this.src; - const newBlob = URL.createObjectURL(await fetchImage(src)); + const img = await fetchImage(src); if (this.src !== src || this.isDestroyed) { - URL.revokeObjectURL(newBlob); // the src has changed, abort + // the src has changed, abort return; } // Check if the blob cache exists now // In this case, someone else already created the blob // Free up the current blob and use the existing one instead - if (usedCache(src)) { - URL.revokeObjectURL(newBlob); - } else { + if (!usedCache(src)) { // Create new blob cache entry - this.dataSrc = newBlob; + this.dataSrc = URL.createObjectURL(img); BLOB_CACHE[src] = [1, this.dataSrc]; } } diff --git a/src/components/frame/XImgCache.ts b/src/components/frame/XImgCache.ts index 999e7ae7..f85cb42d 100644 --- a/src/components/frame/XImgCache.ts +++ b/src/components/frame/XImgCache.ts @@ -84,7 +84,7 @@ async function flushPreviewQueue() { fetchPreviewQueueCopy .filter((p) => p.reqid === reqid) .forEach((p) => { - p.callback(getResponse(imgBlob, imgType, res.headers)); + p.callback?.(getResponse(imgBlob, imgType, res.headers)); p.callback = null; }); }