From 86adec41ba6f85c157d3e4ed0e065ba2f6e43348 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 7 Apr 2020 13:11:35 -0700 Subject: [PATCH] Ping suspended level when canceling its timer Make sure the suspended level is marked as pinged so that we return back to it later, in case the render we're about to start gets aborted. Generally we only reach this path via a ping, but we shouldn't assume that will always be the case. --- packages/react-reconciler/src/ReactFiberWorkLoop.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index 98157fbe44e4e..d24ece936b2df 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -1168,6 +1168,19 @@ function prepareFreshStack(root, expirationTime) { cancelTimeout(timeoutHandle); } + // Check if there's a suspended level at lower priority. + const lastSuspendedTime = root.lastSuspendedTime; + if (lastSuspendedTime !== NoWork && lastSuspendedTime < expirationTime) { + const lastPingedTime = root.lastPingedTime; + // Make sure the suspended level is marked as pinged so that we return back + // to it later, in case the render we're about to start gets aborted. + // Generally we only reach this path via a ping, but we shouldn't assume + // that will always be the case. + if (lastPingedTime === NoWork || lastPingedTime > lastSuspendedTime) { + root.lastPingedTime = lastSuspendedTime; + } + } + if (workInProgress !== null) { let interruptedWork = workInProgress.return; while (interruptedWork !== null) {