@samitouri / QOS-React-2 / commits / 6259d88f03

Simpler way to prevent flushing updates on server

Test Plan: Only failing tests in jest are immutable tests that were already failing.

Ben Alpert committed Jul 21, 2014 at 16:26 UTC 6259d88f0352f0ab4388412122d5c911a6fb9329
2 files changed +9 -20
src/core/ReactCompositeComponent.js
+9 -1
@@ -864,7 +864,15 @@ var ReactCompositeComponentMixin = {
864 replaceState: function(completeState, callback) {
865 validateLifeCycleOnReplaceState(this);
866 this._pendingState = completeState;
867 - ReactUpdates.enqueueUpdate(this, callback);
867 + if (this._compositeLifeCycleState !== CompositeLifeCycle.MOUNTING) {
868 + // If we're in a componentWillMount handler, don't enqueue a rerender
869 + // because ReactUpdates assumes we're in a browser context (which is wrong
870 + // for server rendering) and we're about to do a render anyway.
871 + // TODO: The callback here is ignored when setState is called from
872 + // componentWillMount. Either fix it or disallow doing so completely in
873 + // favor of getInitialState.
874 + ReactUpdates.enqueueUpdate(this, callback);
875 + }
876 },
877
878 /**
src/core/ReactUpdates.js
-19
@@ -172,25 +172,6 @@ var flushBatchedUpdates = ReactPerf.measure(
172 // componentDidUpdate) but we need to check here too in order to catch
173 // updates enqueued by setState callbacks.
174 while (dirtyComponents.length) {
175 - var allUnmounted = true;
176 - for (var i = 0, l = dirtyComponents.length; i < l; i++) {
177 - if (dirtyComponents[i].isMounted()) {
178 - allUnmounted = false;
179 - break;
180 - }
181 - }
182 -
183 - if (allUnmounted) {
184 - // All the "dirty" components are unmounted, which probably means that
185 - // they were marked dirty due to setState calls in componentWillMount
186 - // handlers and the components are currently in the process of mounting.
187 - // `runBatchedUpdates` will be a noop. In that case, initializing the
188 - // DOM-dependent ReactReconcileTransaction is thus not what we want to
189 - // do, especially when using server rendering, so we skip it.
190 - dirtyComponents.length = 0;
191 - return;
192 - }
193 -
175 var transaction = ReactUpdatesFlushTransaction.getPooled();
176 transaction.perform(runBatchedUpdates, null, transaction);
177 ReactUpdatesFlushTransaction.release(transaction);