diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 785f3421..28001a8a 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -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) { @@ -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) @@ -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))