@samitouri / QOS-React-2 / commits / 0267cfbb8f

Fix ReactDOMSelection to avoid erroring on Firefox's anonymous divs

Saif Hakim committed Sep 22, 2015 at 04:30 UTC 0267cfbb8fba0ef78a33353a911718c46a9336ff
1 file changed +16
src/renderers/dom/client/ReactDOMSelection.js
+16
@@ -76,6 +76,22 @@ function getModernOffsets(node) {
76
77 var currentRange = selection.getRangeAt(0);
78
79 + // In Firefox, range.startContainer and range.endContainer can be "anonymous
80 + // divs", e.g. the up/down buttons on an <input type="number">. Anonymous
81 + // divs do not seem to expose properties, triggering a "Permission denied
82 + // error" if any of its properties are accessed. The only seemingly possible
83 + // way to avoid erroring is to access a property that typically works for
84 + // non-anonymous divs and catch any error that may otherwise arise. See
85 + // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
86 + try {
87 + /* eslint-disable no-unused-expressions */
88 + currentRange.startContainer.nodeType;
89 + currentRange.endContainer.nodeType;
90 + /* eslint-enable no-unused-expressions */
91 + } catch (e) {
92 + return null;
93 + }
94 +
95 // If the node and offset values are the same, the selection is collapsed.
96 // `Selection.isCollapsed` is available natively, but IE sometimes gets
97 // this value wrong.