From 58dc368adbf7cd44f46777beb0ab51792c9da02a Mon Sep 17 00:00:00 2001 From: Quang Huynh Date: Thu, 3 Dec 2020 16:59:12 +1100 Subject: [PATCH 1/4] Fixes scrollListener accesses properties of null --- src/InfiniteScroll.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/InfiniteScroll.js b/src/InfiniteScroll.js index 332f7bd..d2c1d95 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -192,6 +192,13 @@ export default class InfiniteScroll extends Component { const scrollEl = window; const parentNode = this.getParentElement(el); + // The el could be null due to scroll event being fired while the scroll component no long exists. + // Early exit would prevent properties of the null el (and null parent) being accessed in offset + // calculation below. + if (!el) { + return; + } + let offset; if (this.props.useWindow) { const doc = From 5d8f2b6dabe066b1435211f197ad79cb3cab642f Mon Sep 17 00:00:00 2001 From: Quang Huynh Date: Thu, 3 Dec 2020 19:29:49 +1100 Subject: [PATCH 2/4] . --- src/InfiniteScroll.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/InfiniteScroll.js b/src/InfiniteScroll.js index d2c1d95..724f72a 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -188,17 +188,18 @@ 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); - // The el could be null due to scroll event being fired while the scroll component no long exists. - // Early exit would prevent properties of the null el (and null parent) being accessed in offset - // calculation below. - if (!el) { - return; - } - let offset; if (this.props.useWindow) { const doc = From 76bdbfd002217573a20fe34506a7da7c288b7257 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 31 May 2021 22:07:40 +0800 Subject: [PATCH 3/4] Add src changes to dist --- dist/InfiniteScroll.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dist/InfiniteScroll.js b/dist/InfiniteScroll.js index 462ef57..5bcc68a 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); From e3fd7ee22ec99a0760d44b6499bd9530ef28a5c9 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Wed, 2 Jun 2021 16:50:22 +0800 Subject: [PATCH 4/4] Add empty check for last else since component can be removed during the process --- dist/InfiniteScroll.js | 3 ++- src/InfiniteScroll.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/InfiniteScroll.js b/dist/InfiniteScroll.js index 5bcc68a..3d7608b 100644 --- a/dist/InfiniteScroll.js +++ b/dist/InfiniteScroll.js @@ -305,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 724f72a..89a03d9 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -215,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; }