List row render to default height between cache.clear(i) and recomputeRowHeights(i), mess up scrollTop position
See original GitHub issueWe are using List and CellMeasurer in our project, we noticed our list scroll up after cache.clear(10)
is called. After logging everything, here is what happens:
Basic code:
cache.clear(10);
this.ref.recomputeRowHeights(10);
Logs:
- Current List scrollTop: 18440
- Current cached index 10 row height: 130
- We notice item data has changed, So we run
cache.clear(10)
- Log shows
cache.rowHeight()
is running, because index 10 is cleared, it returns our default row - height: 90 - The list height become shorter and re-rendering
recomputeRowHeights(10)
is finally finished- recompute result shows new height is still 130, Current cached index 10 row height set to 130 again.
- Log shows
cache.rowHeight()
is running again, The list height become taller and re-rendering - onScroll event on List is triggerd, current List scrollTop now auto changed to 18400, exactly the 40 difference between measured height(130) and default height(90).
Basically, cache.clear(index)
causing the list item to re-render at default height. Then recomputeRowHeights(index)
fixes the height but scrollTop is broken due to this.
I am not sure why recomputeRowHeights does not update cache directly. And wondering if there is correct way for handling this.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
List row render to default height between cache.clear(i) and ...
List row render to default height between cache.clear(i) and recomputeRowHeights(i), mess up scrollTop position.
Read more >React Virtualized - Changing the height of a List Row post ...
When height changes externally, let List know to reset its cached size List.recomputeRowHeights() List.forceUpdate().
Read more >Element size and scrolling - The Modern JavaScript Tutorial
Properties scrollLeft/scrollTop are the width/height of the hidden, scrolled out part of the element. On the picture below we can see ...
Read more >Common bugs in React Native ScrollView and how to fix them
FlatList exposes to us a long list of props that are designed for the best UX and performance of rendering long data lists,...
Read more >ag-Grid Row Models: Infinite Scrolling
Infinite scrolling allows the grid to lazy load rows from the server depending on what the scroll position is of the grid. In...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my project I was able to solve this problem (or at least one very similar) by replacing the call to
recomputeRowHeights()
with a call toforceUpdateGrid()
. I have yet to see any problems with this alternative approach, but whether it’s the proper solution I don’t know. The documentation states thatforceUpdateGrid
is useful when data has changed but heights have not, however I suspect (without looking into the source) that when rows have been cleared from the cache, re-rendering the grid also forces CellMeasurer to recompute the row heights, while bypassing the step where default heights are used.Any news on how to fix this? I’m running into the same issue.