From 444895b7dc2dca9d369be53b17f30fa2fb08eb40 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Tue, 5 Nov 2024 18:32:44 +0900 Subject: [PATCH] wrap with guard block Co-authored-by: Sebastian "Sebbie" Silbermann --- packages/next/src/server/lib/lru-cache.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/next/src/server/lib/lru-cache.ts b/packages/next/src/server/lib/lru-cache.ts index ef7abd722750c..18c6cde741c59 100644 --- a/packages/next/src/server/lib/lru-cache.ts +++ b/packages/next/src/server/lib/lru-cache.ts @@ -69,11 +69,13 @@ export class LRUCache { } private evictLeastRecentlyUsed(): void { - const lruKey = this.cache.keys().next().value || '' - const lruSize = this.sizes.get(lruKey) || 0 - this.totalSize -= lruSize - this.cache.delete(lruKey) - this.sizes.delete(lruKey) + const lruKey = this.cache.keys().next().value + if (lruKey !== undefined) { + const lruSize = this.sizes.get(lruKey) || 0 + this.totalSize -= lruSize + this.cache.delete(lruKey) + this.sizes.delete(lruKey) + } } reset() {