diff --git a/src/renderers/dom/server/ReactServerRendering.js b/src/renderers/dom/server/ReactServerRendering.js index ee57e07438e98..02db894ef3336 100644 --- a/src/renderers/dom/server/ReactServerRendering.js +++ b/src/renderers/dom/server/ReactServerRendering.js @@ -25,6 +25,8 @@ var emptyObject = require('emptyObject'); var instantiateReactComponent = require('instantiateReactComponent'); var invariant = require('invariant'); +var pendingTransactions = 0; + /** * @param {ReactElement} element * @return {string} the HTML markup @@ -36,6 +38,8 @@ function renderToStringImpl(element, makeStaticMarkup) { transaction = ReactServerRenderingTransaction.getPooled(makeStaticMarkup); + pendingTransactions++; + return transaction.perform(function() { if (__DEV__) { ReactInstrumentation.debugTool.onBeginFlush(); @@ -60,10 +64,15 @@ function renderToStringImpl(element, makeStaticMarkup) { return markup; }, null); } finally { + pendingTransactions--; ReactServerRenderingTransaction.release(transaction); // Revert to the DOM batching strategy since these two renderers // currently share these stateful modules. - ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy); + if (!pendingTransactions) { + ReactUpdates.injection.injectBatchingStrategy( + ReactDefaultBatchingStrategy + ); + } } } diff --git a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js index 0ebabbfd67ae2..5b5d1bd7221b3 100644 --- a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js +++ b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js @@ -399,5 +399,36 @@ describe('ReactServerRendering', function() { ); expect(markup.indexOf('hello, world') >= 0).toBe(true); }); + + it('renders components with different batching strategies', function() { + var StaticComponent = React.createClass({ + render: function() { + const staticContent = ReactServerRendering.renderToStaticMarkup( +
+ +
+ ); + return
; + }, + }); + + var Component = React.createClass({ + componentWillMount: function() { + this.setState({text: 'hello, world'}); + }, + render: function() { + return
{this.state.text}
; + }, + }); + expect( + ReactServerRendering.renderToString.bind( + ReactServerRendering, +
+ + +
+ ) + ).not.toThrow(); + }); }); });