question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List row render to default height between cache.clear(i) and recomputeRowHeights(i), mess up scrollTop position

See original GitHub issue

We 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:open
  • Created 6 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
imenshacommented, Mar 7, 2018

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 to forceUpdateGrid(). 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 that forceUpdateGrid 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.

1reaction
jcarroll2007commented, Mar 12, 2018

Any news on how to fix this? I’m running into the same issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found