Fix for wrong ref call order

master v1.0.14
Vitaliy Filippov 2019-11-15 18:04:30 +03:00
parent ba46a65559
commit ea707b2c08
3 changed files with 18 additions and 4 deletions

View File

@ -61,8 +61,10 @@ export function virtualScrollDriver(props, oldState, getRenderedItemHeight)
lastItemSize = getRenderedItemHeight(props.totalItems - 1 - lastVisibleItems);
if (!lastItemSize)
{
// Some required items in the end are missing
return newState;
// Some required items in the end are missing, complain about it loudly, but don't break scrolling
// eslint-disable-next-line
console.error('dynamic-virtual-scroll: item #'+(props.totalItems - 1 - lastVisibleItems)+' is missing from render, please fix your code');
lastItemSize = 0;
}
lastItemsHeight += lastItemSize < props.minRowHeight ? props.minRowHeight : lastItemSize;
lastVisibleItems++;

View File

@ -36,10 +36,22 @@ export class VirtualScrollList extends React.Component
setItemRef = []
itemRefs = []
itemRefCount = []
makeRef(i)
{
this.setItemRef[i] = (e) => this.itemRefs[i] = e;
this.setItemRef[i] = (e) =>
{
// If the new row instance is mounted before unmouting the old one,
// we get called 2 times in wrong order: first with the new instance,
// then with null telling us that the old one is unmounted.
// We track reference count to workaround it.
this.itemRefCount[i] = (this.itemRefCount[i]||0) + (e ? 1 : -1);
if (e || !this.itemRefCount[i])
{
this.itemRefs[i] = e;
}
};
}
renderItems(start, count, is_end)

View File

@ -1,6 +1,6 @@
{
"name": "dynamic-virtual-scroll",
"version": "1.0.13",
"version": "1.0.14",
"author": {
"name": "Vitaliy Filippov",
"email": "vitalif@yourcmc.ru",