From 64b51dff37dbc385532a56ed19e23a9da1437385 Mon Sep 17 00:00:00 2001 From: Jainil Parekh Date: Thu, 19 Dec 2019 06:00:39 -0800 Subject: [PATCH] IE could not display composer when opening or creating a new group chat from the chat create view Summary: When opening a group chat from workplace chat's new message in IE the first invocation of interfaceselection.addRange throws an unspecified error. Remarkably, subsequent invocations work fine and draft editor is able to continue as usual. This typically happens when IE doesn't like something but it is very hard to suss out what the root cause is. So I'm wrapping with a try catch so that this does not crash the draft editor completely. Reviewed By: danielbuechele Differential Revision: D19163859 fbshipit-source-id: ded92cae390dfca8d8956a49c1be54b1540b2998 --- .../selection/setDraftEditorSelection.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/component/selection/setDraftEditorSelection.js b/src/component/selection/setDraftEditorSelection.js index 88d53f8e18..db55bdcba1 100644 --- a/src/component/selection/setDraftEditorSelection.js +++ b/src/component/selection/setDraftEditorSelection.js @@ -15,6 +15,7 @@ import type SelectionState from 'SelectionState'; const DraftEffects = require('DraftEffects'); const DraftJsDebugLogging = require('DraftJsDebugLogging'); +const UserAgent = require('UserAgent'); const containsNode = require('containsNode'); const getActiveElement = require('getActiveElement'); @@ -22,6 +23,8 @@ const getCorrectDocumentFromNode = require('getCorrectDocumentFromNode'); const invariant = require('invariant'); const isElement = require('isElement'); +const isIE = UserAgent.isBrowser('IE'); + function getAnonymizedDOM( node: Node, getNodeLabels?: (n: Node) => Array, @@ -332,7 +335,17 @@ function addPointToSelection( DraftEffects.handleExtensionCausedError(); } range.setStart(node, offset); - selection.addRange(range); + + // IE sometimes throws Unspecified Error when trying to addRange + if (isIE) { + try { + selection.addRange(range); + } catch { + // ignore + } + } else { + selection.addRange(range); + } } module.exports = {