From fd9335135a77d0bf7145b5ff7b0e8464f50061a0 Mon Sep 17 00:00:00 2001 From: chinesepowered Date: Tue, 7 Apr 2026 09:48:26 -0700 Subject: [PATCH] fix(core): reorder LruCache entries on get() for falsy values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LruCache.get() guarded the LRU reorder with 'if (value)' — a truthy check that skipped the reorder when the cached value was 0, '', false, or null. The value was still returned correctly, but it stayed in its original insertion-order slot rather than being promoted to most- recently-used, so legitimate falsy values were evicted earlier than they should have been. Switch to Map.has() for existence so all values — truthy or not — get the reorder. --- packages/core/src/utils/LruCache.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/src/utils/LruCache.ts b/packages/core/src/utils/LruCache.ts index 076828c459..9780b85af7 100644 --- a/packages/core/src/utils/LruCache.ts +++ b/packages/core/src/utils/LruCache.ts @@ -14,12 +14,13 @@ export class LruCache { } get(key: K): V | undefined { - const value = this.cache.get(key); - if (value) { - // Move to end to mark as recently used - this.cache.delete(key); - this.cache.set(key, value); + if (!this.cache.has(key)) { + return undefined; } + const value = this.cache.get(key) as V; + // Move to end to mark as recently used + this.cache.delete(key); + this.cache.set(key, value); return value; }