From 40b7c19a890b04e5d7bd1273e4f90bb78769ae5b Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Thu, 18 Jun 2015 12:40:44 -0700 Subject: [PATCH] Use a custom batching strategy for server rendering This simply ignores any enqueued actions. This means that we don't have to have special logic for componentWillMount. It is just that those updates are never enqueued. --- .../dom/server/ReactServerBatchingStrategy.js | 22 +++++++++++++++++++ .../dom/server/ReactServerRendering.js | 13 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/renderers/dom/server/ReactServerBatchingStrategy.js diff --git a/src/renderers/dom/server/ReactServerBatchingStrategy.js b/src/renderers/dom/server/ReactServerBatchingStrategy.js new file mode 100644 index 0000000000..2621847ac0 --- /dev/null +++ b/src/renderers/dom/server/ReactServerBatchingStrategy.js @@ -0,0 +1,22 @@ +/** + * Copyright 2014-2015, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule ReactServerBatchingStrategy + * @typechecks + */ + +'use strict'; + +var ReactServerBatchingStrategy = { + isBatchingUpdates: false, + batchedUpdates: function(callback) { + // Don't do anything + } +}; + +module.exports = ReactServerBatchingStrategy; diff --git a/src/renderers/dom/server/ReactServerRendering.js b/src/renderers/dom/server/ReactServerRendering.js index 8341dde538..9cfb3bfaf0 100644 --- a/src/renderers/dom/server/ReactServerRendering.js +++ b/src/renderers/dom/server/ReactServerRendering.js @@ -11,11 +11,14 @@ */ 'use strict'; +var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy'); var ReactElement = require('ReactElement'); var ReactInstanceHandles = require('ReactInstanceHandles'); var ReactMarkupChecksum = require('ReactMarkupChecksum'); +var ReactServerBatchingStrategy = require('ReactServerBatchingStrategy'); var ReactServerRenderingTransaction = require('ReactServerRenderingTransaction'); +var ReactUpdates = require('ReactUpdates'); var emptyObject = require('emptyObject'); var instantiateReactComponent = require('instantiateReactComponent'); @@ -33,6 +36,8 @@ function renderToString(element) { var transaction; try { + ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy); + var id = ReactInstanceHandles.createReactRootID(); transaction = ReactServerRenderingTransaction.getPooled(false); @@ -44,6 +49,9 @@ function renderToString(element) { }, null); } finally { ReactServerRenderingTransaction.release(transaction); + // Revert to the DOM batching strategy since these two renderers + // currently share these stateful modules. + ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy); } } @@ -60,6 +68,8 @@ function renderToStaticMarkup(element) { var transaction; try { + ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy); + var id = ReactInstanceHandles.createReactRootID(); transaction = ReactServerRenderingTransaction.getPooled(true); @@ -69,6 +79,9 @@ function renderToStaticMarkup(element) { }, null); } finally { ReactServerRenderingTransaction.release(transaction); + // Revert to the DOM batching strategy since these two renderers + // currently share these stateful modules. + ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy); } }