You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At @discord we use use FlashList to render the list of channels in a server. When you switch servers, we want to update the channel list so that the selected channel in that server is in view; this means we need to call scrollToIndex to move the user to the right index.
The issue we often see is that this leads to some pretty unfortunate jank. It goes something like this:
User is on Server A where the currently selected channel is at index 5
1a. We use initialScrollIndex to make sure it starts rendering at the right offset
User switches to Server B where the channel is at index 25
The data array changes with all the new channels
FlashList renders with the new data
In a useLayoutEffect we attempt to scroll to the new index with scrollToIndex
Often times this leads to FlashList doing more work than needed, where it renders the channels for the wrong offset and then we correct it by calling scrollToIndex in that layout effect. We see a few scenarios, depending on how timings shake out:
Switching servers takes longer because it has to render the new list items, scroll, and then render again
There is visible jank where FlashList appears to commit the changes for the new data and then the scroll updates the list
I'm wondering: is a more performant way to update the scroll offset when data changes? Ideally we could tell FlashList that when data changes, it should start rendering from a new scroll index; listening for changes to initialScrollIndex could do that, though it only seems to work for the initial mount and that would probably be a breaking change.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
At @discord we use use
FlashList
to render the list of channels in a server. When you switch servers, we want to update the channel list so that the selected channel in that server is in view; this means we need to callscrollToIndex
to move the user to the right index.The issue we often see is that this leads to some pretty unfortunate jank. It goes something like this:
Server A
where the currently selected channel is at index5
1a. We use
initialScrollIndex
to make sure it starts rendering at the right offsetServer B
where the channel is at index25
data
array changes with all the new channelsFlashList
renders with the newdata
useLayoutEffect
we attempt to scroll to the new index withscrollToIndex
Often times this leads to
FlashList
doing more work than needed, where it renders the channels for the wrong offset and then we correct it by callingscrollToIndex
in that layout effect. We see a few scenarios, depending on how timings shake out:FlashList
appears to commit the changes for the newdata
and then the scroll updates the listI'm wondering: is a more performant way to update the scroll offset when
data
changes? Ideally we could tellFlashList
that whendata
changes, it should start rendering from a new scroll index; listening for changes toinitialScrollIndex
could do that, though it only seems to work for the initial mount and that would probably be a breaking change.Beta Was this translation helpful? Give feedback.
All reactions