Legend List 2.0 focuses on accuracy and performance
Version 2 of Legend List (@legendapp/list) is out. Its release page says it is faster, more accurate, and smaller. It introduces no breaking changes, but because it is nearly a full rewrite, the project is treating it as a major version.
The update centers on accuracy and performance. The maintainVisibleContentPosition algorithm was rewritten to be more accurate and performant, which also let the team remove many hacks, workarounds and management code. That simpler implementation made new features such as sticky headers possible. Several additions target advanced customization for complex lists like AI chats.
Improvements
Accuracy
- Accurate
initialScrollIndex,scrollToIndex, andscrollToEnd - Bidirectional infinite scroll without flashing or jumpiness
- Average sizes are used after the first render, so
estimatedItemSizeis now optional
Scroll performance
maintainVisibleContentPositionis now enabled by default- Fewer and smaller renders while updating positions
- More efficient container recycling
New features
- Sticky headers: a
stickyIndicesprop keeps headers visible while scrolling - Item types:
getItemTypecategorizes items for performance optimization, andgetFixedItemSizehandles items with known fixed sizes.renderItem,getFixedItemSize, andgetEstimatedItemSizenow receive an item type parameter - Lazy list: built-in lazy list support directly in the
LegendListcomponent - Scroll position: a
snapToIndicesprop snaps scrolling to specific item indices - Hooks and refs: a
useSyncLayouthook for synchronizing layout operations, a ref function to enable or disable scroll processing, andgetState()now includespositionAtIndexanddata - Code quality: most functionality was extracted into small, testable functions, and extensive test infrastructure was added
Migration
Most changes are backward compatible. The one change to note is that maintainVisibleContentPosition now defaults to true. The project says it has no significant overhead and is required for accurate initialScrollIndex, scrollToIndex, and infinite scrolling up.
Links
Source: legendapp.com