Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes scrollListener accesses properties of null #280

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion dist/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -207,7 +215,8 @@ export default class InfiniteScroll extends Component {
}
} else if (this.props.isReverse) {
offset = parentNode.scrollTop;
} else {
} else if (el) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is else if needed? Isn't el a ref for this.scrollComponent?

// ScrollComponent can be already removed
offset = el.scrollHeight - parentNode.scrollTop - parentNode.clientHeight;
}

Expand Down