Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
check top of node instead of bottom, since coming in from last
Browse files Browse the repository at this point in the history
as we're approaching from the last node, if we're scrolled up,
the first node we encounter would be below the bottom of the viewport

change the logic to stop at the first node that has its top
above the viewport bottom.

When completely scrolled up, this was causing nodes way below
the viewport to be selected as the reference for the pixelOffset,
and when pagination came in, it would immediately try to apply
the big negative pixelOffset, scrolling to a negative scrollTop,
thus going to the top again, and triggering another pagination,
entering in an infinite pagination loop until you scrolled down.
  • Loading branch information
bwindels committed Feb 26, 2019
1 parent 4203079 commit c920dd2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/structures/ScrollPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,20 +609,16 @@ module.exports = React.createClass({
const itemlist = this.refs.itemlist;
const messages = itemlist.children;
let node = null;
let nodeBottom;

// loop backwards, from bottom-most message (as that is the most common case)
for (let i = messages.length-1; i >= 0; --i) {
if (!messages[i].dataset.scrollTokens) {
continue;
}
node = messages[i];

nodeBottom = node.offsetTop + node.clientHeight;
// If the bottom of the panel intersects the ClientRect of node, use this node
// as the scrollToken.
// If this is false for the entire for-loop, we default to the last node
// (which is why newScrollState is set on every iteration).
if (nodeBottom >= scrollBottom) {
// break at the first message (coming from the bottom)
// that has it's offsetTop above the bottom of the viewport.
if (node.offsetTop < scrollBottom) {
// Use this node as the scrollToken
break;
}
Expand All @@ -633,6 +629,7 @@ module.exports = React.createClass({
return;
}

const nodeBottom = node.offsetTop + node.clientHeight;
debuglog("ScrollPanel: saved scroll state", this.scrollState);
this.scrollState = {
stuckAtBottom: false,
Expand Down

0 comments on commit c920dd2

Please sign in to comment.