]> Untitled Git - lemmy-ui.git/commitdiff
Fix comment scroll bug. Fixes #492
authorDessalines <tyhou13@gmx.com>
Thu, 18 Nov 2021 15:37:24 +0000 (10:37 -0500)
committerDessalines <tyhou13@gmx.com>
Thu, 18 Nov 2021 15:37:24 +0000 (10:37 -0500)
src/shared/components/post/post.tsx

index 499330cc29c074c4844979cde1ef3836c20b9608..f68d77acc11c2812da7ec2430ad0dc1fca9b29f8 100644 (file)
@@ -218,11 +218,15 @@ export class Post extends Component<any, PostState> {
   }
 
   scrollCommentIntoView() {
-    var elmnt = document.getElementById(`comment-${this.state.commentId}`);
-    elmnt.scrollIntoView();
-    elmnt.classList.add("mark");
-    this.state.scrolled = true;
-    this.markScrolledAsRead(this.state.commentId);
+    let commentElement = document.getElementById(
+      `comment-${this.state.commentId}`
+    );
+    if (commentElement) {
+      commentElement.scrollIntoView();
+      commentElement.classList.add("mark");
+      this.state.scrolled = true;
+      this.markScrolledAsRead(this.state.commentId);
+    }
   }
 
   get checkScrollIntoCommentsParam() {