mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[react] making sure ReactDOMServer always uses ServerReactRootIndex, even on an environment that can use DOM
This commit is contained in:
committed by
Fabio M. Costa
parent
707ffc74fd
commit
e65fe182e7
@@ -11,6 +11,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ClientReactRootIndex = require('ClientReactRootIndex');
|
||||
var DOMProperty = require('DOMProperty');
|
||||
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
|
||||
var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
@@ -727,7 +728,9 @@ var ReactMount = {
|
||||
}
|
||||
if (!reactRootID) {
|
||||
// No valid "reactRoot" ID found, create one.
|
||||
reactRootID = ReactInstanceHandles.createReactRootID();
|
||||
reactRootID = ReactInstanceHandles.createReactRootID(
|
||||
ClientReactRootIndex.createReactRootIndex()
|
||||
);
|
||||
}
|
||||
containersByReactRootID[reactRootID] = container;
|
||||
return reactRootID;
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
require('mock-modules')
|
||||
.mock('ServerReactRootIndex');
|
||||
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactDOMServer;
|
||||
@@ -32,6 +35,14 @@ describe('rendering React components at document', function() {
|
||||
beforeEach(function() {
|
||||
require('mock-modules').dumpCache();
|
||||
|
||||
// Negative integer creator. So they won't get confused with
|
||||
// the Client positive ids.
|
||||
var ServerReactRootIndex = require('ServerReactRootIndex');
|
||||
var serverId = -1;
|
||||
ServerReactRootIndex.createReactRootIndex.mockImplementation(function() {
|
||||
return serverId--;
|
||||
});
|
||||
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactDOMServer = require('ReactDOMServer');
|
||||
@@ -213,8 +224,8 @@ describe('rendering React components at document', function() {
|
||||
'quirks by rendering at the document root. You should look for ' +
|
||||
'environment dependent code in your components and ensure ' +
|
||||
'the props are the same client and server side:\n' +
|
||||
' (client) data-reactid=".0.1">Hello world</body></\n' +
|
||||
' (server) data-reactid=".0.1">Goodbye world</body>'
|
||||
' (client) ata-reactid=".-1.1">Hello world</body></\n' +
|
||||
' (server) ata-reactid=".-1.1">Goodbye world</body>'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ var ReactServerBatchingStrategy = require('ReactServerBatchingStrategy');
|
||||
var ReactServerRenderingTransaction =
|
||||
require('ReactServerRenderingTransaction');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
var ServerReactRootIndex = require('ServerReactRootIndex');
|
||||
|
||||
var emptyObject = require('emptyObject');
|
||||
var instantiateReactComponent = require('instantiateReactComponent');
|
||||
@@ -38,7 +39,9 @@ function renderToString(element) {
|
||||
try {
|
||||
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
||||
|
||||
var id = ReactInstanceHandles.createReactRootID();
|
||||
var id = ReactInstanceHandles.createReactRootID(
|
||||
ServerReactRootIndex.createReactRootIndex()
|
||||
);
|
||||
transaction = ReactServerRenderingTransaction.getPooled(false);
|
||||
|
||||
return transaction.perform(function() {
|
||||
@@ -70,7 +73,9 @@ function renderToStaticMarkup(element) {
|
||||
try {
|
||||
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
||||
|
||||
var id = ReactInstanceHandles.createReactRootID();
|
||||
var id = ReactInstanceHandles.createReactRootID(
|
||||
ServerReactRootIndex.createReactRootIndex()
|
||||
);
|
||||
transaction = ReactServerRenderingTransaction.getPooled(true);
|
||||
|
||||
return transaction.perform(function() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
var BeforeInputEventPlugin = require('BeforeInputEventPlugin');
|
||||
var ChangeEventPlugin = require('ChangeEventPlugin');
|
||||
var ClientReactRootIndex = require('ClientReactRootIndex');
|
||||
var DefaultEventPluginOrder = require('DefaultEventPluginOrder');
|
||||
var EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
@@ -30,7 +29,6 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
|
||||
var ReactMount = require('ReactMount');
|
||||
var ReactReconcileTransaction = require('ReactReconcileTransaction');
|
||||
var SelectEventPlugin = require('SelectEventPlugin');
|
||||
var ServerReactRootIndex = require('ServerReactRootIndex');
|
||||
var SimpleEventPlugin = require('SimpleEventPlugin');
|
||||
var SVGDOMPropertyConfig = require('SVGDOMPropertyConfig');
|
||||
|
||||
@@ -90,12 +88,6 @@ function inject() {
|
||||
ReactDefaultBatchingStrategy
|
||||
);
|
||||
|
||||
ReactInjection.RootIndex.injectCreateReactRootIndex(
|
||||
ExecutionEnvironment.canUseDOM ?
|
||||
ClientReactRootIndex.createReactRootIndex :
|
||||
ServerReactRootIndex.createReactRootIndex
|
||||
);
|
||||
|
||||
ReactInjection.Component.injectEnvironment(ReactComponentBrowserEnvironment);
|
||||
|
||||
if (__DEV__) {
|
||||
|
||||
@@ -19,7 +19,6 @@ var ReactEmptyComponent = require('ReactEmptyComponent');
|
||||
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
|
||||
var ReactNativeComponent = require('ReactNativeComponent');
|
||||
var ReactPerf = require('ReactPerf');
|
||||
var ReactRootIndex = require('ReactRootIndex');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
|
||||
var ReactInjection = {
|
||||
@@ -31,7 +30,6 @@ var ReactInjection = {
|
||||
EventEmitter: ReactBrowserEventEmitter.injection,
|
||||
NativeComponent: ReactNativeComponent.injection,
|
||||
Perf: ReactPerf.injection,
|
||||
RootIndex: ReactRootIndex.injection,
|
||||
Updates: ReactUpdates.injection,
|
||||
};
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactRootIndex = require('ReactRootIndex');
|
||||
|
||||
var invariant = require('invariant');
|
||||
|
||||
var SEPARATOR = '.';
|
||||
@@ -221,10 +219,11 @@ var ReactInstanceHandles = {
|
||||
|
||||
/**
|
||||
* Constructs a React root ID
|
||||
* @param {number} index A unique integer
|
||||
* @return {string} A React root ID.
|
||||
*/
|
||||
createReactRootID: function() {
|
||||
return getReactRootIDString(ReactRootIndex.createReactRootIndex());
|
||||
createReactRootID: function(index) {
|
||||
return getReactRootIDString(index);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Copyright 2013-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 ReactRootIndex
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactRootIndexInjection = {
|
||||
/**
|
||||
* @param {function} _createReactRootIndex
|
||||
*/
|
||||
injectCreateReactRootIndex: function(_createReactRootIndex) {
|
||||
ReactRootIndex.createReactRootIndex = _createReactRootIndex;
|
||||
},
|
||||
};
|
||||
|
||||
var ReactRootIndex = {
|
||||
createReactRootIndex: null,
|
||||
injection: ReactRootIndexInjection,
|
||||
};
|
||||
|
||||
module.exports = ReactRootIndex;
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ClientReactRootIndex = require('ClientReactRootIndex');
|
||||
var EventConstants = require('EventConstants');
|
||||
var EventPluginHub = require('EventPluginHub');
|
||||
var EventPropagators = require('EventPropagators');
|
||||
@@ -425,7 +426,9 @@ ReactShallowRenderer.prototype._render = function(element, transaction, context)
|
||||
if (this._instance) {
|
||||
this._instance.receiveComponent(element, transaction, context);
|
||||
} else {
|
||||
var rootID = ReactInstanceHandles.createReactRootID();
|
||||
var rootID = ReactInstanceHandles.createReactRootID(
|
||||
ClientReactRootIndex.createReactRootIndex()
|
||||
);
|
||||
var instance = new ShallowComponentWrapper(element.type);
|
||||
instance.construct(element);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user