Fix scroll jumps in multi-list SolidVirtualList scenarios #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Commit
290bcbdaddedforceUpdatetoVirtual.updateUniqueIdsto ensuredataSourcechanges are reflected immediately in single-list scenarios, fixing stale rendering and covering growing/shrinking lists. However, in applications with multipleSolidVirtualListinstances (e.g., multiple virtualized lists in a single parent component), this caused unintended scroll jumps. Parent re-renders triggered thecreateEffectfordataSourceIdsin all instances, callingupdateUniqueIdsandforceUpdateeven when theirdataSourcewas unchanged, leading to unnecessary range updates and scroll position shifts.Approach
To maintain the benefits of
290bcbd(immediate updates for modified lists) while preventing scroll jumps in multi-list setups, I've optimizedSolidVirtualList’s reactivity to ensureupdateUniqueIdsis only called when a list’sdataSourceIDs change. I also improved initial rendering to avoid unnecessary updates.Changes
dataSource: AddedmemoizedDataSourceusingcreateMemoto preventdataSourceIdsrecomputation when thedataSourceprop reference changes but content is identical.prevIdsSignal: Introduced aprevIdssignal to track previousdataSourceIds. ThecreateEffectnow checks ifdataSourceIdsdiffers fromprevIdsbefore callingupdateUniqueIds, preventing unnecessaryforceUpdatecalls.Impact
290bcbd’s fix for immediate updates in single-list scenarios.Test
SolidVirtualListinstances in a parent component which shares a common state data store.dataSourcedoes not affect others’ scroll positions.dataSourceupdates redraw correctly per290bcbd).Notes
SolidVirtualListfor efficiency. Alternatively, theprevIdslogic could be moved toVirtual.updateUniqueIdsfor framework-agnostic use, but this is less idiomatic for SolidJS.ResizeObserverinVirtualListItemfor added stability.290bcbd.