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

Commit 225fe67

Browse files
committed
Fix room change sometimes being very slow
If the js-sdk had a lot of history in memory for a particular room, riot would paginate all that history into the DOM and render it when switching to that room (before then removing it all again). This obviously made switching to that room very slow. This was caused by the fact that we relied on the setState that happens in TimelinePanel after the pagination taking effect such that ScrollPanel sees that it no longer needs to paginate, but in some situations (as far as I can see, in electron...?) this setState would not take effect until the pagination stopped fulfiling requests from memory and hit the network. Fix: don't resolve the promise returned by the pagination request until the setState has actually happened.
1 parent 32b33c6 commit 225fe67

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/structures/TimelinePanel.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,20 @@ var TimelinePanel = React.createClass({
344344
newState[canPaginateOtherWayKey] = true;
345345
}
346346

347-
this.setState(newState);
347+
// Don't resolve until the setState has completed: we need to let
348+
// the component update before we consider the pagination commpleted,
349+
// otherwise we'll end up paginating in all the history the js-sdk
350+
// has in memory because we never gave the component a chance to scroll
351+
// itself into the right place
352+
let resolveSetStatePromise;
353+
const setStatePromise = new Promise(function(resolve) {
354+
resolveSetStatePromise = resolve;
355+
});
356+
this.setState(newState, () => {
357+
resolveSetStatePromise(r);
358+
});
348359

349-
return r;
360+
return setStatePromise;
350361
});
351362
},
352363

0 commit comments

Comments
 (0)