Skip to content

Commit

Permalink
fix: read getItemKey from options
Browse files Browse the repository at this point in the history
  • Loading branch information
piecyk committed Aug 19, 2024
1 parent aff750d commit 0034303
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ export class Virtualizer<

if (!measureElement) {
measureElement = (node: TItemElement | null | undefined) => {
const key = getItemKey(i)
const key = this.options.getItemKey(i)
const prevNode = this.elementsCache.get(key)

if (!node) {
Expand Down Expand Up @@ -751,9 +751,8 @@ export class Virtualizer<
entry: ResizeObserverEntry | undefined,
) => {
const i = this.indexFromElement(node)
const item = this.getMeasurements()[i]

if (!item || !node.isConnected) {
if (!node.isConnected) {
this.elementsCache.forEach((cached, key) => {
if (cached === node) {
this.observer.unobserve(node)
Expand All @@ -763,14 +762,16 @@ export class Virtualizer<
return
}

const prevNode = this.elementsCache.get(item.key)
const itemKey = this.options.getItemKey(i)

const prevNode = this.elementsCache.get(itemKey)

if (prevNode !== node) {
if (prevNode) {
this.observer.unobserve(prevNode)
}
this.observer.observe(node)
this.elementsCache.set(item.key, node)
this.elementsCache.set(itemKey, node)
}

this.resizeItem(i, this.options.measureElement(node, entry, this))
Expand Down

0 comments on commit 0034303

Please sign in to comment.