Skip to content

Commit f97fa62

Browse files
committed
Fix: Missing null check in LRU cleanup
Unfortunately this field is not strongly typed because it's a cyclic type and I wasn't able to soundly model it with TypeScript. Skill issue I'm sure. Don't have an exact repro yet but the previous code was obviously wrong. The way this should have been structured regardless is to delete the wrapper MapEntry object instead of the value it contains. The non-nullness of the wrapper object _is_ properly typed, and avoids an unnecessary indirection. As a follow up, I'll look into how to model this type properly.
1 parent 940f889 commit f97fa62

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/next/src/client/components/segment-cache/cache-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ function dropRef<V extends MapValue>(value: V): void {
396396
value.ref = null
397397
}
398398

399-
function deleteMapEntry<V extends MapValue>(entry: MapEntry<V>): void {
399+
export function deleteMapEntry<V extends MapValue>(entry: MapEntry<V>): void {
400400
// Delete the entry from the cache.
401401
const emptyEntry: EmptyMapEntry<V> = entry as any
402402
emptyEntry.value = null

packages/next/src/client/components/segment-cache/lru.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MapEntry } from './cache-map'
2-
import { deleteFromCacheMap } from './cache-map'
2+
import { deleteMapEntry } from './cache-map'
33

44
// We use an LRU for memory management. We must update this whenever we add or
55
// remove a new cache entry, or when an entry changes size.
@@ -119,7 +119,7 @@ function cleanup() {
119119
if (tail !== null) {
120120
// Delete the entry from the map. In turn, this will remove it from
121121
// the LRU.
122-
deleteFromCacheMap(tail.value)
122+
deleteMapEntry(tail)
123123
}
124124
}
125125
}

0 commit comments

Comments
 (0)