From 3df4089e3df662edcd704cd9cb9e3968d447e537 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Mar 2026 03:34:40 +0000 Subject: [PATCH] Fix thumbnail cache key collisions causing wrong images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cache key was using only src.slice(0, 200) which is not unique — different base64 images share the same MIME prefix and similar headers. Now samples from multiple positions (start, middle, end) plus length to virtually eliminate collisions. https://claude.ai/code/session_01MvD1n4QeXutgwUpKJuDGHa --- src/store/thumbnailCache.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/store/thumbnailCache.ts b/src/store/thumbnailCache.ts index b2bd19ec..8505b615 100644 --- a/src/store/thumbnailCache.ts +++ b/src/store/thumbnailCache.ts @@ -8,9 +8,11 @@ const cache = new Map(); const pending = new Map>(); function cacheKey(src: string): string { - // Use a slice of the data URL that's unique enough to identify the image. - // Skip the "data:image/...;base64," prefix (~30 chars) and take the next 120 chars. - return src.slice(0, 200); + // Sample from multiple positions + length to create a collision-resistant key + // without hashing the entire multi-MB string. + const len = src.length; + const mid = len >>> 1; + return `${len}:${src.slice(30, 90)}:${src.slice(mid, mid + 60)}:${src.slice(-60)}`; } export function getThumbnail(src: string): string | undefined {