Skip to content

Commit 2587e92

Browse files
authored
fix(lit-virtual): create Virtualizer instance before hostConnected (#1061)
1 parent 94761ff commit 2587e92

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/hip-eels-speak.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@tanstack/lit-virtual': patch
3+
---
4+
5+
fix(lit-virtual): create Virtualizer instance before hostConnected
6+
7+
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`.

packages/lit-virtual/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class VirtualizerControllerBase<
2525
host: ReactiveControllerHost,
2626
options: VirtualizerOptions<TScrollElement, TItemElement>,
2727
) {
28-
;(this.host = host).addController(this)
29-
3028
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
3129
...options,
3230
onChange: (instance, sync) => {
@@ -35,13 +33,14 @@ class VirtualizerControllerBase<
3533
},
3634
}
3735
this.virtualizer = new Virtualizer(resolvedOptions)
36+
;(this.host = host).addController(this)
3837
}
3938

4039
public getVirtualizer() {
4140
return this.virtualizer
4241
}
4342

44-
async hostConnected() {
43+
hostConnected() {
4544
this.cleanup = this.virtualizer._didMount()
4645
}
4746

0 commit comments

Comments
 (0)