Skip to content

Commit

Permalink
Fix some iframe edge cases
Browse files Browse the repository at this point in the history
Should fix #13648 by being as protective in `setOffsets` than in `getOffsets`
  • Loading branch information
JSteunou authored and Jérôme Steunou committed Sep 14, 2018
1 parent 8bc0bca commit 9a5eaed
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/react-dom/src/client/ReactDOMSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ export function getModernOffsetsFromPoints(
* @param {object} offsets
*/
export function setOffsets(node, offsets) {
const doc = node.ownerDocument || document;
const win = doc ? doc.defaultView : window;
const selection = win.getSelection();
const {ownerDocument} = node;
const win = (ownerDocument && ownerDocument.defaultView) || window;
const selection = win.getSelection && win.getSelection();
if (!selection) {
return;
}
const length = node.textContent.length;
let start = Math.min(offsets.start, length);
let end = offsets.end === undefined ? start : Math.min(offsets.end, length);
Expand All @@ -179,7 +182,7 @@ export function setOffsets(node, offsets) {
) {
return;
}
const range = doc.createRange();
const range = ownerDocument.createRange();
range.setStart(startMarker.node, startMarker.offset);
selection.removeAllRanges();

Expand Down

0 comments on commit 9a5eaed

Please sign in to comment.