Restore global window.event after event dispatching (#13688) (#13697)
Sergei Startsev committed
Sep 25, 2018 at 18:24 UTC
17e703cb9692c26795c794a54e2239f603ee090d
1 file changed
+11
packages/shared/invokeGuardedCallbackImpl.js
+11
@@ -98,6 +98,13 @@ if (__DEV__) {
98
// browsers that support it.
99
let windowEvent = window.event;
100
101
+ // Keeps track of the descriptor of window.event to restore it after event
102
+ // dispatching: https://github.com/facebook/react/issues/13688
103
+ const windowEventDescriptor = Object.getOwnPropertyDescriptor(
104
+ window,
105
+ 'event',
106
+ );
107
+
108
// Create an event handler for our fake event. We will synchronously
109
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
110
// call the user-provided callback.
@@ -172,6 +179,10 @@ if (__DEV__) {
179
evt.initEvent(evtType, false, false);
180
fakeNode.dispatchEvent(evt);
181
182
+ if (windowEventDescriptor) {
183
+ Object.defineProperty(window, 'event', windowEventDescriptor);
184
+ }
185
+
186
if (didError) {
187
if (!didSetError) {
188
// The callback errored, but the error event never fired.