Skip to content

Commit 35a202d

Browse files
authored
[react-events] Ensure we restore currentInstance + currentTimers (#16758)
1 parent 3717c25 commit 35a202d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/react-dom/src/events/DOMEventResponderSystem.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ function processTimers(
360360
delay: number,
361361
): void {
362362
const timersArr = Array.from(timers.values());
363+
const previousInstance = currentInstance;
364+
const previousTimers = currentTimers;
363365
try {
364366
batchedEventUpdates(() => {
365367
for (let i = 0; i < timersArr.length; i++) {
@@ -374,8 +376,8 @@ function processTimers(
374376
}
375377
});
376378
} finally {
377-
currentTimers = null;
378-
currentInstance = null;
379+
currentTimers = previousTimers;
380+
currentInstance = previousInstance;
379381
currentTimeStamp = 0;
380382
}
381383
}
@@ -518,14 +520,16 @@ export function mountEventResponder(
518520
) {
519521
const onMount = responder.onMount;
520522
if (onMount !== null) {
523+
const previousInstance = currentInstance;
524+
const previousTimers = currentTimers;
521525
currentInstance = responderInstance;
522526
try {
523527
batchedEventUpdates(() => {
524528
onMount(eventResponderContext, props, state);
525529
});
526530
} finally {
527-
currentInstance = null;
528-
currentTimers = null;
531+
currentInstance = previousInstance;
532+
currentTimers = previousTimers;
529533
}
530534
}
531535
}
@@ -537,14 +541,16 @@ export function unmountEventResponder(
537541
const onUnmount = responder.onUnmount;
538542
if (onUnmount !== null) {
539543
let {props, state} = responderInstance;
544+
const previousInstance = currentInstance;
545+
const previousTimers = currentTimers;
540546
currentInstance = responderInstance;
541547
try {
542548
batchedEventUpdates(() => {
543549
onUnmount(eventResponderContext, props, state);
544550
});
545551
} finally {
546-
currentInstance = null;
547-
currentTimers = null;
552+
currentInstance = previousInstance;
553+
currentTimers = previousTimers;
548554
}
549555
}
550556
const rootEventTypesSet = responderInstance.rootEventTypes;

0 commit comments

Comments
 (0)