@samitouri / QOS-React-2 / commits / 35a202d0e7

[react-events] Ensure we restore currentInstance + currentTimers (#16758)

Dominic Gannaway committed Sep 12, 2019 at 12:44 UTC 35a202d0e7d7c4ef3c0768cb85ac5e17b6eb03b3
1 file changed +12 -6
packages/react-dom/src/events/DOMEventResponderSystem.js
+12 -6
@@ -360,6 +360,8 @@ function processTimers(
360 delay: number,
361 ): void {
362 const timersArr = Array.from(timers.values());
363 + const previousInstance = currentInstance;
364 + const previousTimers = currentTimers;
365 try {
366 batchedEventUpdates(() => {
367 for (let i = 0; i < timersArr.length; i++) {
@@ -374,8 +376,8 @@ function processTimers(
376 }
377 });
378 } finally {
377 - currentTimers = null;
378 - currentInstance = null;
379 + currentTimers = previousTimers;
380 + currentInstance = previousInstance;
381 currentTimeStamp = 0;
382 }
383 }
@@ -518,14 +520,16 @@ export function mountEventResponder(
520 ) {
521 const onMount = responder.onMount;
522 if (onMount !== null) {
523 + const previousInstance = currentInstance;
524 + const previousTimers = currentTimers;
525 currentInstance = responderInstance;
526 try {
527 batchedEventUpdates(() => {
528 onMount(eventResponderContext, props, state);
529 });
530 } finally {
527 - currentInstance = null;
528 - currentTimers = null;
531 + currentInstance = previousInstance;
532 + currentTimers = previousTimers;
533 }
534 }
535 }
@@ -537,14 +541,16 @@ export function unmountEventResponder(
541 const onUnmount = responder.onUnmount;
542 if (onUnmount !== null) {
543 let {props, state} = responderInstance;
544 + const previousInstance = currentInstance;
545 + const previousTimers = currentTimers;
546 currentInstance = responderInstance;
547 try {
548 batchedEventUpdates(() => {
549 onUnmount(eventResponderContext, props, state);
550 });
551 } finally {
546 - currentInstance = null;
547 - currentTimers = null;
552 + currentInstance = previousInstance;
553 + currentTimers = previousTimers;
554 }
555 }
556 const rootEventTypesSet = responderInstance.rootEventTypes;