Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/hip-eels-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/lit-virtual': patch
---

fix(lit-virtual): create Virtualizer instance before hostConnected

When creating an instance of the reactive controller in `connectedCallback`, calling `addController` will synchronously call `hostConnected` on the controller. This means that `this.virtualizer` will still be `undefined`.
6 changes: 3 additions & 3 deletions packages/lit-virtual/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class VirtualizerControllerBase<
host: ReactiveControllerHost,
options: VirtualizerOptions<TScrollElement, TItemElement>,
) {
;(this.host = host).addController(this)

const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
...options,
onChange: (instance, sync) => {
Expand All @@ -35,13 +33,15 @@ class VirtualizerControllerBase<
},
}
this.virtualizer = new Virtualizer(resolvedOptions)

;(this.host = host).addController(this)
}

public getVirtualizer() {
return this.virtualizer
}

async hostConnected() {
hostConnected() {
this.cleanup = this.virtualizer._didMount()
}

Expand Down