Skip to content

Commit 1f1dba9

Browse files
jimfbzpao
authored andcommitted
Merge pull request facebook#6364 from p-jackson/issue-5700
Don't wrap drag events in IE/Edge in dev builds (cherry picked from commit 2e8f28c)
1 parent 258e591 commit 1f1dba9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/shared/utils/ReactErrorUtils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
'use strict';
1313

14+
var SyntheticDragEvent = require('SyntheticDragEvent');
15+
1416
var caughtError = null;
1517

1618
/**
@@ -65,6 +67,11 @@ if (__DEV__) {
6567
typeof document.createEvent === 'function') {
6668
var fakeNode = document.createElement('react');
6769
ReactErrorUtils.invokeGuardedCallback = function(name, func, a, b) {
70+
if (!canWrapEvent(a)) {
71+
invokeGuardedCallback(name, func, a, b);
72+
return;
73+
}
74+
6875
var boundFunc = func.bind(null, a, b);
6976
var evtType = `react-${name}`;
7077
fakeNode.addEventListener(evtType, boundFunc, false);
@@ -74,6 +81,41 @@ if (__DEV__) {
7481
fakeNode.removeEventListener(evtType, boundFunc, false);
7582
};
7683
}
84+
85+
var cacheCanWrapEvent = null;
86+
87+
/**
88+
* IE and Edge don't allow access to the DataTransfer.dropEffect property when
89+
* it's wrapped in another event. This function detects whether we're in an
90+
* environment that behaves this way.
91+
*
92+
* @param {*} ev Event that is being tested
93+
*/
94+
function canWrapEvent(ev) {
95+
if (!(ev instanceof SyntheticDragEvent)) {
96+
return true;
97+
} else if (cacheCanWrapEvent !== null) {
98+
return cacheCanWrapEvent;
99+
}
100+
101+
var canAccessDropEffect = false;
102+
function handleWrappedEvent() {
103+
try {
104+
ev.dataTransfer.dropEffect; // eslint-disable-line no-unused-expressions
105+
canAccessDropEffect = true;
106+
} catch (e) {}
107+
}
108+
109+
var wrappedEventName = 'react-wrappeddragevent';
110+
var wrappedEvent = document.createEvent('Event');
111+
wrappedEvent.initEvent(wrappedEventName, false, false);
112+
fakeNode.addEventListener(wrappedEventName, handleWrappedEvent, false);
113+
fakeNode.dispatchEvent(wrappedEvent);
114+
fakeNode.removeEventListener(wrappedEventName, handleWrappedEvent, false);
115+
116+
cacheCanWrapEvent = canAccessDropEffect;
117+
return canAccessDropEffect;
118+
}
77119
}
78120

79121
module.exports = ReactErrorUtils;

0 commit comments

Comments
 (0)