Skip to content

Commit

Permalink
Fix some iframe edge cases
Browse files Browse the repository at this point in the history
Should fix facebook#13648 by being as protective in `setOffsets` than in `getOffsets`
  • Loading branch information
JSteunou committed Sep 14, 2018
1 parent 8bc0bca commit 3dcfc6a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/react-dom/src/client/ReactDOMSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ 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 Down

0 comments on commit 3dcfc6a

Please sign in to comment.