fix(lit-virtual): add setOptions to VirtualizerController for reactive option updates #1253
ClosedwaterWang(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/1253/headopened piecyk requested changes
@@ -39,3 +42,7 @@3942 return this.virtualizer4043 }414445+ public setOptions(46+ options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,47+ ) {48+ this.options = { ...this.options, ...options }@@ -39,3 +42,8 @@3942 return this.virtualizer4043 }414445+ public setOptions(46+ options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,47+ ) {48+ this.options = { ...this.options, ...options }49+ const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {@@ -115,0 +120,21 @@120+ private scrollElementRef: Ref<HTMLDivElement> = createRef()121+122+ private virtualizerController: VirtualizerController<123+ HTMLDivElement,124+ Element125+ >126+127+ constructor() {128+ super()129+ this.virtualizerController = new VirtualizerController(this, {130+ getScrollElement: () => this.scrollElementRef.value,131+ count: 10,132+ estimateSize: () => 50,133+ observeElementRect: (_, cb) => {134+ cb({ height, width })135+ },136+ })137+ }138+139+ render() {140+ this.virtualizerController.setOptions({@@ -115,0 +174,21 @@174+ <style>175+ .list {176+ border: 1px solid #e6e4dc;177+ max-width: 100%;178+ }179+ .scroll-container {180+ height: ${height}px;181+ width: ${width}px;182+ overflow-y: auto;183+ }184+ </style>185+ `186+ }187+ }188+189+ const el = await fixture(190+ html`<test-list-setoptions></test-list-setoptions>` as any,191+ )192+ await elementUpdated(el)193+ await waitUntil(194+ () => el.shadowRoot.querySelector('[data-index="15"]'),TkDodo closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
3894b946-067a-4cef-8b91-5dd0190bd6b4📥 Commits
Reviewing files that changed from the base of the PR and between e548dedf7d905d059725f7eb57e8a56319ec7ffa and fe62dbe4e8629cfeddd929166e5d82cab1675e6f.
📒 Files selected for processing (1)
packages/lit-virtual/tests/index.test.ts🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
VirtualizerControllerBasenow supports runtime option updates throughsetOptions(). The update path preserves callbacks, applies merged options to the virtualizer, and triggers its lifecycle. A test verifies that changingcountrenders item index 15.Changes#
Lit virtualizer option updates
packages/lit-virtual/src/index.tssetOptions()to merge updates, rebuildonChange, update the virtualizer, and invoke_willUpdate().packages/lit-virtual/tests/index.test.tsEstimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: ⚪ Minimal · up to
fe62dThis localized change updates reactive virtualizer options and adds focused test coverage; no actionable merge-blocking risk remains beyond normal checks and review.
Sequence Diagram(s)#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning
There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
packages/lit-virtual/tests/index.test.ts
Parsing error: "parserOptions.project" has been provided for
@typescript-eslint/parser. The file was not found in any of the provided project(s): packages/lit-virtual/tests/index.test.tsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share