Skip to content

Commit af57488

Browse files
committed
Also fix #16734
1 parent 10ae68a commit af57488

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/shared/invokeGuardedCallbackImpl.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,7 @@ if (__DEV__) {
116116
'event',
117117
);
118118

119-
// Create an event handler for our fake event. We will synchronously
120-
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
121-
// call the user-provided callback.
122-
const funcArgs = Array.prototype.slice.call(arguments, 3);
123-
function callCallback() {
124-
didCall = true;
119+
function restoreAfterDispatch() {
125120
// We immediately remove the callback from event listeners so that
126121
// nested `invokeGuardedCallback` calls do not clash. Otherwise, a
127122
// nested call would trigger the fake event handlers of any call higher
@@ -138,7 +133,15 @@ if (__DEV__) {
138133
) {
139134
window.event = windowEvent;
140135
}
136+
}
141137

138+
// Create an event handler for our fake event. We will synchronously
139+
// dispatch our fake event using `dispatchEvent`. Inside the handler, we
140+
// call the user-provided callback.
141+
const funcArgs = Array.prototype.slice.call(arguments, 3);
142+
function callCallback() {
143+
didCall = true;
144+
restoreAfterDispatch();
142145
func.apply(context, funcArgs);
143146
didError = false;
144147
}
@@ -195,7 +198,7 @@ if (__DEV__) {
195198
Object.defineProperty(window, 'event', windowEventDescriptor);
196199
}
197200

198-
if (didError) {
201+
if (didCall && didError) {
199202
if (!didSetError) {
200203
// The callback errored, but the error event never fired.
201204
error = new Error(
@@ -226,6 +229,7 @@ if (__DEV__) {
226229
// https://github.com/facebook/react/issues/16734
227230
// https://github.com/facebook/react/issues/16585
228231
// Fall back to the production implementation.
232+
restoreAfterDispatch();
229233
return invokeGuardedCallbackProd.apply(this, arguments);
230234
}
231235
};

0 commit comments

Comments
 (0)