Skip to content

Commit

Permalink
fix: don't clear elementsCache on cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
piecyk committed Sep 4, 2024
1 parent fdcb2af commit 5742533
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ export class Virtualizer<
}

return {
disconnect: () => get()?.disconnect(),
disconnect: () => {
get()?.disconnect()
_ro = null
},
observe: (target: Element) =>
get()?.observe(target, { box: 'border-box' }),
unobserve: (target: Element) => get()?.unobserve(target),
Expand Down Expand Up @@ -444,10 +447,9 @@ export class Virtualizer<
private cleanup = () => {
this.unsubs.filter(Boolean).forEach((d) => d!())
this.unsubs = []
this.observer.disconnect()
this.scrollElement = null
this.targetWindow = null
this.observer.disconnect()
this.elementsCache.clear()
}

_didMount = () => {
Expand Down Expand Up @@ -477,6 +479,10 @@ export class Virtualizer<
this.targetWindow = this.scrollElement?.window ?? null
}

this.elementsCache.forEach((cached) => {
this.observer.observe(cached)
})

this._scrollToOffset(this.getScrollOffset(), {
adjustments: undefined,
behavior: undefined,
Expand Down

0 comments on commit 5742533

Please sign in to comment.