@@ -116,12 +116,7 @@ if (__DEV__) {
116
116
'event' ,
117
117
) ;
118
118
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 ( ) {
125
120
// We immediately remove the callback from event listeners so that
126
121
// nested `invokeGuardedCallback` calls do not clash. Otherwise, a
127
122
// nested call would trigger the fake event handlers of any call higher
@@ -138,7 +133,15 @@ if (__DEV__) {
138
133
) {
139
134
window . event = windowEvent ;
140
135
}
136
+ }
141
137
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 ( ) ;
142
145
func . apply ( context , funcArgs ) ;
143
146
didError = false ;
144
147
}
@@ -195,7 +198,7 @@ if (__DEV__) {
195
198
Object . defineProperty ( window , 'event' , windowEventDescriptor ) ;
196
199
}
197
200
198
- if ( didError ) {
201
+ if ( didCall && didError ) {
199
202
if ( ! didSetError ) {
200
203
// The callback errored, but the error event never fired.
201
204
error = new Error (
@@ -226,6 +229,7 @@ if (__DEV__) {
226
229
// https://github.com/facebook/react/issues/16734
227
230
// https://github.com/facebook/react/issues/16585
228
231
// Fall back to the production implementation.
232
+ restoreAfterDispatch ( ) ;
229
233
return invokeGuardedCallbackProd . apply ( this , arguments ) ;
230
234
}
231
235
} ;
0 commit comments