Skip to content

Commit

Permalink
fix(virtual-core): avoid invalidating getIndexes memo cache on every …
Browse files Browse the repository at this point in the history
…call (#918)

calculateRange() returns a new object busting the memo cache on every call to getIndexes(). Passing the scalar startIndex and endIndex from calculateRange() fixes this issue.
  • Loading branch information
ricsam authored Jan 27, 2025
1 parent 7612473 commit 386aca7
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,28 @@ export class Virtualizer<
)

private getIndexes = memo(
() => [
this.options.rangeExtractor,
this.calculateRange(),
this.options.overscan,
this.options.count,
],
(rangeExtractor, range, overscan, count) => {
return range === null
() => {
let startIndex: number | null = null
let endIndex: number | null = null
const range = this.calculateRange()
if (range) {
startIndex = range.startIndex
endIndex = range.endIndex
}
return [
this.options.rangeExtractor,
this.options.overscan,
this.options.count,
startIndex,
endIndex,
]
},
(rangeExtractor, overscan, count, startIndex, endIndex) => {
return startIndex === null || endIndex === null
? []
: rangeExtractor({
startIndex: range.startIndex,
endIndex: range.endIndex,
startIndex,
endIndex,
overscan,
count,
})
Expand Down

0 comments on commit 386aca7

Please sign in to comment.