diff --git a/dist/InfiniteScroll.js b/dist/InfiniteScroll.js index 462ef57..3d7608b 100644 --- a/dist/InfiniteScroll.js +++ b/dist/InfiniteScroll.js @@ -277,6 +277,13 @@ var InfiniteScroll = (function(_Component) { { key: 'scrollListener', value: function scrollListener() { + // It appears to be the that ScrollComponent can be already removed at the time this method + // is invoked. This early return is needed to prevent the offset calculation from accessing + // properties of a null scrollable component. The early return won't alter logic of method + // as the element is required to be visible to loadMore. + if (!this.scrollComponent) { + return; + } var el = this.scrollComponent; var scrollEl = window; var parentNode = this.getParentElement(el); @@ -298,7 +305,8 @@ var InfiniteScroll = (function(_Component) { } } else if (this.props.isReverse) { offset = parentNode.scrollTop; - } else { + } else if (el) { + // ScrollComponent can be already removed offset = el.scrollHeight - parentNode.scrollTop - parentNode.clientHeight; } diff --git a/src/InfiniteScroll.js b/src/InfiniteScroll.js index 332f7bd..89a03d9 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -188,6 +188,14 @@ export default class InfiniteScroll extends Component { } scrollListener() { + // It appears to be the that ScrollComponent can be already removed at the time this method + // is invoked. This early return is needed to prevent the offset calculation from accessing + // properties of a null scrollable component. The early return won't alter logic of method + // as the element is required to be visible to loadMore. + if (!this.scrollComponent) { + return; + } + const el = this.scrollComponent; const scrollEl = window; const parentNode = this.getParentElement(el); @@ -207,7 +215,8 @@ export default class InfiniteScroll extends Component { } } else if (this.props.isReverse) { offset = parentNode.scrollTop; - } else { + } else if (el) { + // ScrollComponent can be already removed offset = el.scrollHeight - parentNode.scrollTop - parentNode.clientHeight; }