@samitouri / QOS-React-2 / commits / 40b7c19a89

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.

Sebastian Markbage committed Jun 18, 2015 at 12:40 UTC 40b7c19a890b04e5d7bd1273e4f90bb78769ae5b
2 files changed +35
src/renderers/dom/server/ReactServerBatchingStrategy.js new
+22
@@ -0,0 +1,22 @@
1 +/**
2 + * Copyright 2014-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @providesModule ReactServerBatchingStrategy
10 + * @typechecks
11 + */
12 +
13 +'use strict';
14 +
15 +var ReactServerBatchingStrategy = {
16 + isBatchingUpdates: false,
17 + batchedUpdates: function(callback) {
18 + // Don't do anything
19 + }
20 +};
21 +
22 +module.exports = ReactServerBatchingStrategy;
src/renderers/dom/server/ReactServerRendering.js
+13
@@ -11,11 +11,14 @@
11 */
12 'use strict';
13
14 +var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy');
15 var ReactElement = require('ReactElement');
16 var ReactInstanceHandles = require('ReactInstanceHandles');
17 var ReactMarkupChecksum = require('ReactMarkupChecksum');
18 +var ReactServerBatchingStrategy = require('ReactServerBatchingStrategy');
19 var ReactServerRenderingTransaction =
20 require('ReactServerRenderingTransaction');
21 +var ReactUpdates = require('ReactUpdates');
22
23 var emptyObject = require('emptyObject');
24 var instantiateReactComponent = require('instantiateReactComponent');
@@ -33,6 +36,8 @@ function renderToString(element) {
36
37 var transaction;
38 try {
39 + ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
40 +
41 var id = ReactInstanceHandles.createReactRootID();
42 transaction = ReactServerRenderingTransaction.getPooled(false);
43
@@ -44,6 +49,9 @@ function renderToString(element) {
49 }, null);
50 } finally {
51 ReactServerRenderingTransaction.release(transaction);
52 + // Revert to the DOM batching strategy since these two renderers
53 + // currently share these stateful modules.
54 + ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
55 }
56 }
57
@@ -60,6 +68,8 @@ function renderToStaticMarkup(element) {
68
69 var transaction;
70 try {
71 + ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
72 +
73 var id = ReactInstanceHandles.createReactRootID();
74 transaction = ReactServerRenderingTransaction.getPooled(true);
75
@@ -69,6 +79,9 @@ function renderToStaticMarkup(element) {
79 }, null);
80 } finally {
81 ReactServerRenderingTransaction.release(transaction);
82 + // Revert to the DOM batching strategy since these two renderers
83 + // currently share these stateful modules.
84 + ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
85 }
86 }
87