Sheraff / soft-serve-tunes

Self hosted music server on raspberry pi
7 stars 0 forks source link

Virtualized `TrackList` #54

Closed Sheraff closed 1 year ago

Sheraff commented 1 year ago

TrackList exports a useVirtualTracks hook so that any parent can become a virtual list container for very long track lists.

We need to call react-virtual useVirtualizer in the parent for rendering order reasons. But really the entire logic is contained in TrackList and we're just passing props.

Because react-virtual causes many renders and TrackItem is a pretty heavy component, we memo it. Might need to look for better perf optimisations, but this seems to do the trick.

Because of useDragTrack, we need to override the range extractor. Currently we always render every track between the one being dragged and the ones in the viewport. We could probably do better for performance with some maths, but this has seemed fine so far.

Because I wanted to only partially go through the virtualizer (only tracks, not other siblings like the cover), I have to overscan the # of items displayed (react-virtual doesn't calculate the size of the list correctly). There might be a better way than this... (as in more accurate / future-proof / flexible, but it works fine in terms of performance)

TODO