Skip to content

Commit

Permalink
Restore global window.event after event dispatching (#13688) (#13697)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-startsev authored and gaearon committed Sep 25, 2018
1 parent a775a76 commit 17e703c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/shared/invokeGuardedCallbackImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ if (__DEV__) {
// browsers that support it.
let windowEvent = window.event;

// Keeps track of the descriptor of window.event to restore it after event
// dispatching: https://github.com/facebook/react/issues/13688
const windowEventDescriptor = Object.getOwnPropertyDescriptor(
window,
'event',
);

// Create an event handler for our fake event. We will synchronously
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
// call the user-provided callback.
Expand Down Expand Up @@ -172,6 +179,10 @@ if (__DEV__) {
evt.initEvent(evtType, false, false);
fakeNode.dispatchEvent(evt);

if (windowEventDescriptor) {
Object.defineProperty(window, 'event', windowEventDescriptor);
}

if (didError) {
if (!didSetError) {
// The callback errored, but the error event never fired.
Expand Down

0 comments on commit 17e703c

Please sign in to comment.