Fix multiple scrolls to same post in PostStream (#2264)

While more pleasant from an FSM standpoint, comparing the current targetPost to the previous one does not work if goToNumber is called twice in a row for the same post. For instance, if a user clicks the mentions link to a post twice, the post stream breaks.
This commit is contained in:
Alexander Skvortsov 2020-10-01 14:50:54 -04:00 committed by GitHub
parent 8e8cfe28ec
commit 2696f02ce1
2 changed files with 4 additions and 9 deletions

View File

@ -121,15 +121,10 @@ export default class PostStream extends Component {
* Start scrolling, if appropriate, to a newly-targeted post.
*/
triggerScroll() {
if (!this.attrs.targetPost) return;
if (!this.attrs.targetPost || !this.stream.needsScroll) return;
const oldTarget = this.prevTarget;
const newTarget = this.attrs.targetPost;
if (oldTarget) {
if ('number' in oldTarget && oldTarget.number === newTarget.number) return;
if ('index' in oldTarget && oldTarget.index === newTarget.index) return;
}
this.stream.needsScroll = false;
if ('number' in newTarget) {
this.scrollToNumber(newTarget.number, this.stream.animateScroll);
@ -137,8 +132,6 @@ export default class PostStream extends Component {
const backwards = newTarget.index === this.stream.count() - 1;
this.scrollToIndex(newTarget.index, this.stream.animateScroll, backwards);
}
this.prevTarget = newTarget;
}
/**

View File

@ -103,6 +103,7 @@ class PostStreamState {
this.loadPromise = this.loadNearNumber(number);
this.needsScroll = true;
this.targetPost = { number };
this.animateScroll = !noAnimation;
this.number = number;
@ -127,6 +128,7 @@ class PostStreamState {
this.loadPromise = this.loadNearIndex(index);
this.needsScroll = true;
this.targetPost = { index };
this.animateScroll = !noAnimation;
this.index = index;