]> Untitled Git - lemmy-ui.git/commitdiff
Fix comment jumping. Fixes #529 (#576)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 14 Feb 2022 19:10:11 +0000 (14:10 -0500)
committerGitHub <noreply@github.com>
Mon, 14 Feb 2022 19:10:11 +0000 (19:10 +0000)
src/shared/components/post/post.tsx

index 4ae1cc5a5fcc6ecfef08cacb364db76d599a0291..9b59859812f3cfc0b4044c26d970e619ea204af0 100644 (file)
@@ -195,16 +195,7 @@ export class Post extends Component<any, PostState> {
     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<any, PostState> {
       if (this.checkScrollIntoCommentsParam) {
         this.scrollIntoCommentSection();
       }
+
+      if (this.state.commentId && !this.state.scrolled) {
+        this.scrollCommentIntoView();
+      }
     } else if (op == UserOperation.CreateComment) {
       let data = wsJsonToRes<CommentResponse>(msg).data;