From 2696f02ce1b08f4db1a54c2f98f52a36546dd8a8 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:50:54 -0400 Subject: [PATCH] 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. --- framework/core/js/src/forum/components/PostStream.js | 11 ++--------- framework/core/js/src/forum/states/PostStreamState.js | 2 ++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/framework/core/js/src/forum/components/PostStream.js b/framework/core/js/src/forum/components/PostStream.js index 37ee017ae..a80f75bec 100644 --- a/framework/core/js/src/forum/components/PostStream.js +++ b/framework/core/js/src/forum/components/PostStream.js @@ -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; } /** diff --git a/framework/core/js/src/forum/states/PostStreamState.js b/framework/core/js/src/forum/states/PostStreamState.js index 2c827bff3..8f93e8f1f 100644 --- a/framework/core/js/src/forum/states/PostStreamState.js +++ b/framework/core/js/src/forum/states/PostStreamState.js @@ -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;