From b6e383791e2bdab0b59602d9ba8f03382797809b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 14 Feb 2022 14:07:54 -0500 Subject: [PATCH] Fix comment jumping. Fixes #529 --- src/shared/components/post/post.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 4ae1cc5a..9b598598 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -195,16 +195,7 @@ export class Post extends Component { document.addEventListener("scroll", this.commentScrollDebounced); } - componentDidUpdate(_lastProps: any, lastState: PostState) { - if ( - this.state.commentId && - !this.state.scrolled && - lastState.postRes && - lastState.postRes.comments.length > 0 - ) { - this.scrollCommentIntoView(); - } - + componentDidUpdate(_lastProps: any) { // Necessary if you are on a post and you click another post (same route) if (_lastProps.location.pathname !== _lastProps.history.location.pathname) { // TODO Couldnt get a refresh working. This does for now. @@ -548,6 +539,10 @@ export class Post extends Component { if (this.checkScrollIntoCommentsParam) { this.scrollIntoCommentSection(); } + + if (this.state.commentId && !this.state.scrolled) { + this.scrollCommentIntoView(); + } } else if (op == UserOperation.CreateComment) { let data = wsJsonToRes(msg).data;