From ba46a65559b7081c350877b278585db2c31ac8fc Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 10 Oct 2019 16:56:10 +0300 Subject: [PATCH] Fix "infinite update loop" when item count changes off-screen --- VirtualScrollList.js | 8 +++++--- package.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/VirtualScrollList.js b/VirtualScrollList.js index 19a9b55..f0eab70 100644 --- a/VirtualScrollList.js +++ b/VirtualScrollList.js @@ -63,9 +63,10 @@ export class VirtualScrollList extends React.Component render() { if (this.state.totalItems && this.props.totalItems != this.state.totalItems && - this.state.scrollTimes <= 0) + this.state.scrollTimes <= 0 && this.viewport && this.viewport.offsetParent) { - // Automatically preserve scroll position when item count changes + // Automatically preserve scroll position when item count changes... + // But only when the list is on-screen! We'll end up with an infinite update loop if it's off-screen. this.state.scrollTo = this.getItemScrollPos(); this.state.scrollTimes = 2; } @@ -132,7 +133,8 @@ export class VirtualScrollList extends React.Component componentDidUpdate = () => { let changed = this.driver(); - if (!changed && this.state.scrollTimes > 0 && this.props.totalItems > 0) + if (!changed && this.state.scrollTimes > 0 && this.props.totalItems > 0 && + this.viewport && this.viewport.offsetParent) { // FIXME: It would be better to find a way to put this logic back into virtual-scroll-driver let pos = this.state.scrollTo; diff --git a/package.json b/package.json index 939a950..140388c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dynamic-virtual-scroll", - "version": "1.0.12", + "version": "1.0.13", "author": { "name": "Vitaliy Filippov", "email": "vitalif@yourcmc.ru",