Describe the bug
constructor(
host: ReactiveControllerHost,
options: VirtualizerOptions<TScrollElement, TItemElement>,
) {
;(this.host = host).addController(this)
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {
...options,
onChange: (instance, sync) => {
this.host.updateComplete.then(() => this.host.requestUpdate())
options.onChange?.(instance, sync)
},
}
this.virtualizer = new Virtualizer(resolvedOptions)
}
When the constructor is called for an already connected custom element, calling addController will cause hostConnected to be called. This then fails because this.virtualizer is still undefined at that point.
Cannot read properties of undefined (reading '_didMount')
async hostConnected() {
this.cleanup = this.virtualizer._didMount()
}
Your minimal, reproducible example
Steps to reproduce
Move construction of the reactive controller in an example to connectedCallback.
Expected behavior
Not throw an error
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
tanstack-virtual version
latest
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct
Describe the bug
When the constructor is called for an already connected custom element, calling
addControllerwill causehostConnectedto be called. This then fails becausethis.virtualizeris stillundefinedat that point.Cannot read properties of undefined (reading '_didMount')Your minimal, reproducible example
Steps to reproduce
Move construction of the reactive controller in an example to
connectedCallback.Expected behavior
Not throw an error
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
tanstack-virtual version
latest
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct