lit-virtual: VirtualizerController never applies updated options after construction
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Inizia da packages/lit-virtual/src/index.ts e segui come VirtualizerController riceve le opzioni durante la costruzione e le aggiorna durante hostUpdated(). Confronta i pattern degli adapter react-virtual, angular-virtual e lit-table menzionati nell’issue, quindi definisci un percorso di aggiornamento delle opzioni il cui comportamento completato applichi i valori modificati, come count, nei render successivi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
VirtualizerController (packages/lit-virtual/src/index.ts) never calls setOptions() after the initial construction, so reactive option updates (a changed count, estimateSize, getScrollElement, etc.) never reach the underlying Virtualizer instance.
constructor(
host: ReactiveControllerHost,
options: VirtualizerOptions<TScrollElement, TItemElement>,
) {
...
this.virtualizer = new Virtualizer(resolvedOptions) // options captured once, here
;(this.host = host).addController(this)
}
hostUpdated() {
this.virtualizer._willUpdate() // no setOptions() call
}
Every other adapter calls setOptions() on every render/update before _willUpdate(). For comparison, react-virtual's useVirtualizer:
instance.setOptions(resolvedOptions)
...
return instance._willUpdate()
and angular-virtual:
virtualizer.setOptions(resolvedOptions())
...
reactiveVirtualizer()._willUpdate()
lit-table's equivalent TableController (same Lit ReactiveController shape, different package) does call the table-core equivalent of setOptions on every access, so this isn't a Lit-specific limitation, lit-virtual just doesn't do it.
Since VirtualizerController is meant to be instantiated once in the host's constructor (the documented usage pattern, same as any other Lit ReactiveController), there's no way for a consumer to get a changed count or other option applied short of reaching into getVirtualizer() and calling .setOptions() manually, which isn't documented anywhere and defeats the point of passing options to the constructor in the first place.
Your minimal, reproducible example
import { LitElement, html } from 'lit'
import { VirtualizerController } from '@tanstack/lit-virtual'
class MyList extends LitElement {
count = 10
virtualizerController = new VirtualizerController(this, {
count: this.count,
estimateSize: () => 35,
getScrollElement: () => this.renderRoot.querySelector('#scroller'),
})
grow() {
this.count = 1000
this.requestUpdate()
}
render() {
const virtualizer = this.virtualizerController.getVirtualizer()
// virtualizer.options.count is still 10 after grow(), even though
// this.count is 1000 and the component re-rendered
return html`<div id="scroller">${virtualizer.getVirtualItems().length} items</div>`
}
}
Steps to reproduce
- Create a
VirtualizerControllerwith an initialcount. - Change the value backing
countand callrequestUpdate()on the host. - Read
virtualizer.options.count(or observe the rendered item count), it still reflects the value from construction time.
Expected behavior
Option changes on subsequent renders should reach the virtualizer, the same as every other framework adapter.
Worth noting this needs more than adding a setOptions() call inside hostUpdated(): the constructor is the only place options is ever received (options: VirtualizerOptions<...>, not a getter), so even a hostUpdated() call would just re-apply the same closed-over object from construction time. The API shape itself doesn't have a channel for fresh options to flow in after construction. lit-table's TableController sidesteps this by exposing a .table(tableOptions, selector) method that's called fresh from render() on every pass rather than once from the constructor, that shape (or an equivalent public setOptions() method consumers call from render()) looks like the fix, not just wiring hostUpdated() to an already-stale value.
Platform
n/a, framework-adapter logic (packages/lit-virtual/src/index.ts)
- Lingua principale
- TypeScript
- Stelle
- 7.1k
- Fork
- 472
- Merge medio
- 1g 14h
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/virtual
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
TanStack/virtual#1307 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
anchorTo: 'end' loses the end when the scroll element shrinksForse già presa @langleyd l’ha presa 5 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
virtual-core: desktop Safari drops the prepend anchor write when history lands during the top rubber-band bounceForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
-
marko-virtual: scrollToEnd during an in-flight prepend strands the view one prepend above the bottom (chat-pretext e2e fails on CI)Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
TanStack/virtual#1252 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/virtual
Issue simili
-
cleanName keeps a state code that's joined to the word before it (SavannahGa → "Savannah Ga")Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
openwatersio/slackwater-database#281 ·
I maintainer di solito rispondono entro 1 giorno
-
accepted bug via-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pingdotgg/t3code#18690 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Bayern feature:Application ready web
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
digitalfabrik/entitlementcard#3176 ·
I maintainer di solito rispondono entro 7 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
NanmiCoder/cc-haha#1533 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno