mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[react-events] Ensure we restore currentInstance + currentTimers (#16758)
This commit is contained in:
+12
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user