From f8eab2f1a9a6b4fb2a7f685a47bb4363e52c2399 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Thu, 27 Nov 2025 00:53:35 +0100 Subject: [PATCH] fix(assets): cache in useImage --- app/composables/useImages.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/composables/useImages.ts b/app/composables/useImages.ts index f69c4bf..9d47e67 100644 --- a/app/composables/useImages.ts +++ b/app/composables/useImages.ts @@ -1,15 +1,16 @@ +const imageCache = new Map(); + export const useImages = (...paths: string[]) => { const images = paths.map((path) => { + if (imageCache.has(path)) { + return imageCache.get(path)!; + } + const img = document.createElement("img"); img.src = path; - return img; - }); + imageCache.set(path, img); - onBeforeUnmount(() => { - images.forEach((img) => { - img.src = ""; - img.remove(); - }); + return img; }); return images;