From a27a0d704712a3d3386e8229f438eb94bf8e7992 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 27 Jul 2020 22:48:18 -0400 Subject: [PATCH] Fix flushing suspense fallbacks at the end of Act when the scheduler is mocked --- packages/react-reconciler/src/ReactFiberWorkLoop.new.js | 9 ++++++++- packages/react-reconciler/src/ReactFiberWorkLoop.old.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 0540d53df5534..3479c73d6e357 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -3717,7 +3717,7 @@ function finishPendingInteractions(root, committedLanes) { // access to the same internals that we do here. Some trade offs in the // implementation no longer make sense. -let isFlushingAct = false; +let isFlushingAct = null; let isInsideThisAct = false; // TODO: Yes, this is confusing. See above comment. We'll refactor it. @@ -3726,6 +3726,13 @@ function shouldForceFlushFallbacksInDEV() { // Never force flush in production. This function should get stripped out. return false; } + + // `isFlushingAct` is used by ReactTestRenderer version of `act`. + if (isFlushingAct != null) { + // Flush callbacks at the end. + return isFlushingAct; + } + // `IsThisRendererActing.current` is used by ReactTestUtils version of `act`. if (IsThisRendererActing.current) { // `isInsideAct` is only used by the reconciler implementation of `act`. diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js index 2a696878563f0..c1d5182e29fce 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.old.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.old.js @@ -3573,7 +3573,7 @@ function finishPendingInteractions(root, committedLanes) { // access to the same internals that we do here. Some trade offs in the // implementation no longer make sense. -let isFlushingAct = false; +let isFlushingAct = null; let isInsideThisAct = false; // TODO: Yes, this is confusing. See above comment. We'll refactor it. @@ -3582,6 +3582,13 @@ function shouldForceFlushFallbacksInDEV() { // Never force flush in production. This function should get stripped out. return false; } + + // `isFlushingAct` is used by ReactTestRenderer version of `act`. + if (isFlushingAct != null) { + // Flush callbacks at the end. + return isFlushingAct; + } + // `IsThisRendererActing.current` is used by ReactTestUtils version of `act`. if (IsThisRendererActing.current) { // `isInsideAct` is only used by the reconciler implementation of `act`.