Skip to content

Commit 17e703c

Browse files
sergei-startsevgaearon
authored andcommitted
Restore global window.event after event dispatching (#13688) (#13697)
1 parent a775a76 commit 17e703c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/shared/invokeGuardedCallbackImpl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ if (__DEV__) {
9898
// browsers that support it.
9999
let windowEvent = window.event;
100100

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+
101108
// Create an event handler for our fake event. We will synchronously
102109
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
103110
// call the user-provided callback.
@@ -172,6 +179,10 @@ if (__DEV__) {
172179
evt.initEvent(evtType, false, false);
173180
fakeNode.dispatchEvent(evt);
174181

182+
if (windowEventDescriptor) {
183+
Object.defineProperty(window, 'event', windowEventDescriptor);
184+
}
185+
175186
if (didError) {
176187
if (!didSetError) {
177188
// The callback errored, but the error event never fired.

0 commit comments

Comments
 (0)