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:
cache.clear(10)cache.rowHeight() is running, because index 10 is cleared, it returns our default row - height: 90recomputeRowHeights(10) is finally finishedcache.rowHeight() is running again, The list height become taller and re-renderingBasically, 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.
Can you provide either a failing unit test _or_ a repro that shows this happening? You can start by forking one of these:
@bvaughn Sure. Here is a simple plnkr example:
https://plnkr.co/edit/8r8VVEMMzqO9BEYLiXr8?p=preview
You should able to see scroll bar jump back after clear cache, despite the new measured row height not change at all.
Cool. Thanks!
I am seeing the same issue on my end. I鈥檓 inserting data above the current index, but after a proper lifecycle cache.clear() and list.recomputeRowHeights() scrollTop doesn鈥檛 recompute properly. It鈥檚 happening exactly the same way as being reported. I will also work on a Plinkr to show what鈥檚 happening. :)
not sure if it's exactly the same issue, but this is happening for me except its with grids. I have 2 grids (header, body). When body column changes (length of data input changes) the body columns recalculate properly. Each odd update call recomputes the header grid size properly, but every even update call resets it to the default size. This causes a jumping effect in the size of the header grid.
+1
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.
Any news on how to fix this? I'm running into the same issue.
For me it worked to use measure rather than recomputeRowHeights, as suggested here: https://stackoverflow.com/questions/47168920/resetting-row-heights-causes-incorrect-row-offset-to-get-calculated
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 thatforceUpdateGridis 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.
That solution solved the issue for me!
Thanks a lot!
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 thatforceUpdateGridis 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.
This issue looks like still remaining. I was also able to fix it thanks to @imensha.
Most helpful comment
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 that
forceUpdateGridis 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.