From 35a202d0e7d7c4ef3c0768cb85ac5e17b6eb03b3 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 12 Sep 2019 12:44:05 +0200 Subject: [PATCH] [react-events] Ensure we restore currentInstance + currentTimers (#16758) --- .../src/events/DOMEventResponderSystem.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react-dom/src/events/DOMEventResponderSystem.js b/packages/react-dom/src/events/DOMEventResponderSystem.js index c960b4aa0e616..c2a0c089c02aa 100644 --- a/packages/react-dom/src/events/DOMEventResponderSystem.js +++ b/packages/react-dom/src/events/DOMEventResponderSystem.js @@ -360,6 +360,8 @@ function processTimers( delay: number, ): void { const timersArr = Array.from(timers.values()); + const previousInstance = currentInstance; + const previousTimers = currentTimers; try { batchedEventUpdates(() => { for (let i = 0; i < timersArr.length; i++) { @@ -374,8 +376,8 @@ function processTimers( } }); } finally { - currentTimers = null; - currentInstance = null; + currentTimers = previousTimers; + currentInstance = previousInstance; currentTimeStamp = 0; } } @@ -518,14 +520,16 @@ export function mountEventResponder( ) { const onMount = responder.onMount; if (onMount !== null) { + const previousInstance = currentInstance; + const previousTimers = currentTimers; currentInstance = responderInstance; try { batchedEventUpdates(() => { onMount(eventResponderContext, props, state); }); } finally { - currentInstance = null; - currentTimers = null; + currentInstance = previousInstance; + currentTimers = previousTimers; } } } @@ -537,14 +541,16 @@ export function unmountEventResponder( const onUnmount = responder.onUnmount; if (onUnmount !== null) { let {props, state} = responderInstance; + const previousInstance = currentInstance; + const previousTimers = currentTimers; currentInstance = responderInstance; try { batchedEventUpdates(() => { onUnmount(eventResponderContext, props, state); }); } finally { - currentInstance = null; - currentTimers = null; + currentInstance = previousInstance; + currentTimers = previousTimers; } } const rootEventTypesSet = responderInstance.rootEventTypes;