From 27ff8bb146635c7ab0b23f6c5fe7c847b298a483 Mon Sep 17 00:00:00 2001
From: Jonathan <jonfritz@gmail.com>
Date: Thu, 27 Jul 2017 08:17:47 -0400
Subject: PLT-7128: Added an undefined check around the scrollIntoView()
 command to avoid trying to scroll to something that has gone out of scope
 (#6998)

---
 webapp/components/create_comment.jsx | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

(limited to 'webapp/components/create_comment.jsx')

diff --git a/webapp/components/create_comment.jsx b/webapp/components/create_comment.jsx
index 858f4c68c..a7edb6bc4 100644
--- a/webapp/components/create_comment.jsx
+++ b/webapp/components/create_comment.jsx
@@ -397,8 +397,11 @@ export default class CreateComment extends React.Component {
         draft.fileInfos = draft.fileInfos.concat(fileInfos);
         PostStore.storeCommentDraft(this.props.rootId, draft);
 
-        // Focus on preview if needed
-        this.refs.preview.refs.container.scrollIntoView();
+        // Focus on preview if needed/possible - if user has switched teams since starting the file upload,
+        // the preview will be undefined and the switch will fail
+        if (typeof this.refs.preview != 'undefined' && this.refs.preview) {
+            this.refs.preview.refs.container.scrollIntoView();
+        }
 
         const enableAddButton = this.handleEnableAddButton(draft.message, draft.fileInfos);
 
-- 
cgit v1.2.3-1-g7c22

