From fb9107b3bc2dc6dff6b4fc062f6ea6ee1257685a Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Wed, 15 Mar 2017 06:37:17 -0700 Subject: [PATCH] Add guards for Firefox and Safari compatibility Addresses https://github.com/facebook/react/pull/7936#issuecomment-270568409 and https://github.com/summernote/summernote/issues/1057 --- .../dom/client/ReactInputSelection.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/renderers/dom/client/ReactInputSelection.js b/src/renderers/dom/client/ReactInputSelection.js index 1dd54c0bd6dad..00c88b299ad91 100644 --- a/src/renderers/dom/client/ReactInputSelection.js +++ b/src/renderers/dom/client/ReactInputSelection.js @@ -41,22 +41,27 @@ function getElementsWithSelections(acc, win) { var doc; try { doc = win.document; + if (!doc) { + return acc; + } } catch (e) { return acc; } var element = null; if (win.getSelection) { var selection = win.getSelection(); - var startNode = selection.anchorNode; - var endNode = selection.focusNode; - var startOffset = selection.anchorOffset; - var endOffset = selection.focusOffset; - if (startNode && startNode.childNodes.length) { - if (startNode.childNodes[startOffset] === endNode.childNodes[endOffset]) { - element = startNode.childNodes[startOffset]; - } - } else { - element = startNode; + if (selection) { + var startNode = selection.anchorNode; + var endNode = selection.focusNode; + var startOffset = selection.anchorOffset; + var endOffset = selection.focusOffset; + if (startNode && startNode.childNodes.length) { + if (startNode.childNodes[startOffset] === endNode.childNodes[endOffset]) { + element = startNode.childNodes[startOffset]; + } + } else { + element = startNode; + } } } else if (doc.selection) { var range = doc.selection.createRange();