From 5f49b63bde09567fb3d52a13e3e264dfcda5cac6 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Sat, 5 Nov 2016 14:37:43 -0700 Subject: [PATCH] Move setState callback to right after didUpdate (#8204) It's much easier to do it this way in Fiber and there shouldn't be much observable difference. --- scripts/fiber/tests-failing.txt | 1 - scripts/fiber/tests-passing.txt | 1 + .../shared/stack/reconciler/ReactUpdates.js | 16 ++-------------- .../reconciler/__tests__/ReactUpdates-test.js | 10 +++++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index e714208e1fb04..8e08011932621 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -575,7 +575,6 @@ src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js * should flow updates correctly * should share reconcile transaction across different roots * should queue mount-ready handlers across different roots -* should flush updates in the correct order * should flush updates in the correct order across roots * should queue updates from during mount * calls asap callbacks properly diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 397164670dd78..dc27a2cea8889 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1165,6 +1165,7 @@ src/renderers/shared/stack/reconciler/__tests__/ReactStatelessComponent-test.js src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js * should not reconcile children passed via props +* should flush updates in the correct order * should queue nested updates * calls componentWillReceiveProps setState callback properly * does not update one component twice in a batch (#2410) diff --git a/src/renderers/shared/stack/reconciler/ReactUpdates.js b/src/renderers/shared/stack/reconciler/ReactUpdates.js index 643b4ea426c5e..e1dd560e356c6 100644 --- a/src/renderers/shared/stack/reconciler/ReactUpdates.js +++ b/src/renderers/shared/stack/reconciler/ReactUpdates.js @@ -53,21 +53,11 @@ var NESTED_UPDATES = { }, }; -var UPDATE_QUEUEING = { - initialize: function() { - this.callbackQueue.reset(); - }, - close: function() { - this.callbackQueue.notifyAll(); - }, -}; - -var TRANSACTION_WRAPPERS = [NESTED_UPDATES, UPDATE_QUEUEING]; +var TRANSACTION_WRAPPERS = [NESTED_UPDATES]; function ReactUpdatesFlushTransaction() { this.reinitializeTransaction(); this.dirtyComponentsLength = null; - this.callbackQueue = CallbackQueue.getPooled(); this.reconcileTransaction = ReactUpdates.ReactReconcileTransaction.getPooled( /* useCreateElement */ true ); @@ -83,8 +73,6 @@ Object.assign( destructor: function() { this.dirtyComponentsLength = null; - CallbackQueue.release(this.callbackQueue); - this.callbackQueue = null; ReactUpdates.ReactReconcileTransaction.release(this.reconcileTransaction); this.reconcileTransaction = null; }, @@ -179,7 +167,7 @@ function runBatchedUpdates(transaction) { if (callbacks) { for (var j = 0; j < callbacks.length; j++) { - transaction.callbackQueue.enqueue( + transaction.reconcileTransaction.getReactMountReady().enqueue( callbacks[j], component.getPublicInstance() ); diff --git a/src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js b/src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js index 044e709b4b382..14cb726e4259e 100644 --- a/src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js +++ b/src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js @@ -634,8 +634,8 @@ describe('ReactUpdates', () => { 'Inner-setState-1', 'Inner-render-1-1', 'Inner-didUpdate-1-1', - 'Inner-callback-1', - 'Outer-callback-1', + 'Inner-callback-1', + 'Outer-callback-1', 'Outer-setState-2', 'Outer-render-2', @@ -643,10 +643,10 @@ describe('ReactUpdates', () => { 'Inner-didUpdate-2-1', 'Outer-didUpdate-2', 'Inner-setState-2', - 'Inner-render-2-2', - 'Inner-didUpdate-2-2', + 'Outer-callback-2', + 'Inner-render-2-2', + 'Inner-didUpdate-2-2', 'Inner-callback-2', - 'Outer-callback-2', ]); /* eslint-enable indent */ });