File tree 1 file changed +15
-10
lines changed
packages/react-dom/src/client
1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -38,22 +38,27 @@ function getElementsWithSelections(acc, win) {
38
38
var doc ;
39
39
try {
40
40
doc = win . document ;
41
+ if ( ! doc ) {
42
+ return acc ;
43
+ }
41
44
} catch ( e ) {
42
45
return acc ;
43
46
}
44
47
var element = null ;
45
48
if ( win . getSelection ) {
46
49
var selection = win . getSelection ( ) ;
47
- var startNode = selection . anchorNode ;
48
- var endNode = selection . focusNode ;
49
- var startOffset = selection . anchorOffset ;
50
- var endOffset = selection . focusOffset ;
51
- if ( startNode && startNode . childNodes . length ) {
52
- if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
53
- element = startNode . childNodes [ startOffset ] ;
54
- }
55
- } else {
56
- element = startNode ;
50
+ if ( selection ) {
51
+ var startNode = selection . anchorNode ;
52
+ var endNode = selection . focusNode ;
53
+ var startOffset = selection . anchorOffset ;
54
+ var endOffset = selection . focusOffset ;
55
+ if ( startNode && startNode . childNodes . length ) {
56
+ if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
57
+ element = startNode . childNodes [ startOffset ] ;
58
+ }
59
+ } else {
60
+ element = startNode ;
61
+ }
57
62
}
58
63
} else if ( doc . selection ) {
59
64
var range = doc . selection . createRange ( ) ;
You can’t perform that action at this time.
0 commit comments