[react] making sure ReactDOMServer always uses ServerReactRootIndex, even on an environment that can use DOM
Fabio Costa committed
Sep 22, 2015 at 16:11 UTC
e65fe182e799002365efa88965e8b640b7e65eaf
8 files changed
+31
-49
src/renderers/dom/client/ReactMount.js
+4
-1
@@ -11,6 +11,7 @@
11
12
'use strict';
13
14
+var ClientReactRootIndex = require('ClientReactRootIndex');
15
var DOMProperty = require('DOMProperty');
16
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
17
var ReactCurrentOwner = require('ReactCurrentOwner');
@@ -727,7 +728,9 @@ var ReactMount = {
728
}
729
if (!reactRootID) {
730
// No valid "reactRoot" ID found, create one.
730
- reactRootID = ReactInstanceHandles.createReactRootID();
731
+ reactRootID = ReactInstanceHandles.createReactRootID(
732
+ ClientReactRootIndex.createReactRootIndex()
733
+ );
734
}
735
containersByReactRootID[reactRootID] = container;
736
return reactRootID;
src/renderers/dom/client/__tests__/ReactRenderDocument-test.js
+13
-2
@@ -11,6 +11,9 @@
11
12
'use strict';
13
14
+require('mock-modules')
15
+ .mock('ServerReactRootIndex');
16
+
17
var React;
18
var ReactDOM;
19
var ReactDOMServer;
@@ -32,6 +35,14 @@ describe('rendering React components at document', function() {
35
beforeEach(function() {
36
require('mock-modules').dumpCache();
37
38
+ // Negative integer creator. So they won't get confused with
39
+ // the Client positive ids.
40
+ var ServerReactRootIndex = require('ServerReactRootIndex');
41
+ var serverId = -1;
42
+ ServerReactRootIndex.createReactRootIndex.mockImplementation(function() {
43
+ return serverId--;
44
+ });
45
+
46
React = require('React');
47
ReactDOM = require('ReactDOM');
48
ReactDOMServer = require('ReactDOMServer');
@@ -213,8 +224,8 @@ describe('rendering React components at document', function() {
224
'quirks by rendering at the document root. You should look for ' +
225
'environment dependent code in your components and ensure ' +
226
'the props are the same client and server side:\n' +
216
- ' (client) data-reactid=".0.1">Hello world</body></\n' +
217
- ' (server) data-reactid=".0.1">Goodbye world</body>'
227
+ ' (client) ata-reactid=".-1.1">Hello world</body></\n' +
228
+ ' (server) ata-reactid=".-1.1">Goodbye world</body>'
229
);
230
});
231
src/renderers/dom/server/ReactServerRendering.js
+7
-2
@@ -19,6 +19,7 @@ var ReactServerBatchingStrategy = require('ReactServerBatchingStrategy');
19
var ReactServerRenderingTransaction =
20
require('ReactServerRenderingTransaction');
21
var ReactUpdates = require('ReactUpdates');
22
+var ServerReactRootIndex = require('ServerReactRootIndex');
23
24
var emptyObject = require('emptyObject');
25
var instantiateReactComponent = require('instantiateReactComponent');
@@ -38,7 +39,9 @@ function renderToString(element) {
39
try {
40
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
41
41
- var id = ReactInstanceHandles.createReactRootID();
42
+ var id = ReactInstanceHandles.createReactRootID(
43
+ ServerReactRootIndex.createReactRootIndex()
44
+ );
45
transaction = ReactServerRenderingTransaction.getPooled(false);
46
47
return transaction.perform(function() {
@@ -70,7 +73,9 @@ function renderToStaticMarkup(element) {
73
try {
74
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
75
73
- var id = ReactInstanceHandles.createReactRootID();
76
+ var id = ReactInstanceHandles.createReactRootID(
77
+ ServerReactRootIndex.createReactRootIndex()
78
+ );
79
transaction = ReactServerRenderingTransaction.getPooled(true);
80
81
return transaction.perform(function() {
src/renderers/dom/shared/ReactDefaultInjection.js
-8
@@ -13,7 +13,6 @@
13
14
var BeforeInputEventPlugin = require('BeforeInputEventPlugin');
15
var ChangeEventPlugin = require('ChangeEventPlugin');
16
-var ClientReactRootIndex = require('ClientReactRootIndex');
16
var DefaultEventPluginOrder = require('DefaultEventPluginOrder');
17
var EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
18
var ExecutionEnvironment = require('ExecutionEnvironment');
@@ -30,7 +29,6 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
29
var ReactMount = require('ReactMount');
30
var ReactReconcileTransaction = require('ReactReconcileTransaction');
31
var SelectEventPlugin = require('SelectEventPlugin');
33
-var ServerReactRootIndex = require('ServerReactRootIndex');
32
var SimpleEventPlugin = require('SimpleEventPlugin');
33
var SVGDOMPropertyConfig = require('SVGDOMPropertyConfig');
34
@@ -90,12 +88,6 @@ function inject() {
88
ReactDefaultBatchingStrategy
89
);
90
93
- ReactInjection.RootIndex.injectCreateReactRootIndex(
94
- ExecutionEnvironment.canUseDOM ?
95
- ClientReactRootIndex.createReactRootIndex :
96
- ServerReactRootIndex.createReactRootIndex
97
- );
98
-
91
ReactInjection.Component.injectEnvironment(ReactComponentBrowserEnvironment);
92
93
if (__DEV__) {
src/renderers/dom/shared/ReactInjection.js
-2
@@ -19,7 +19,6 @@ var ReactEmptyComponent = require('ReactEmptyComponent');
19
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
20
var ReactNativeComponent = require('ReactNativeComponent');
21
var ReactPerf = require('ReactPerf');
22
-var ReactRootIndex = require('ReactRootIndex');
22
var ReactUpdates = require('ReactUpdates');
23
24
var ReactInjection = {
@@ -31,7 +30,6 @@ var ReactInjection = {
30
EventEmitter: ReactBrowserEventEmitter.injection,
31
NativeComponent: ReactNativeComponent.injection,
32
Perf: ReactPerf.injection,
34
- RootIndex: ReactRootIndex.injection,
33
Updates: ReactUpdates.injection,
34
};
35
src/renderers/shared/reconciler/ReactInstanceHandles.js
+3
-4
@@ -12,8 +12,6 @@
12
13
'use strict';
14
15
-var ReactRootIndex = require('ReactRootIndex');
16
-
15
var invariant = require('invariant');
16
17
var SEPARATOR = '.';
@@ -221,10 +219,11 @@ var ReactInstanceHandles = {
219
220
/**
221
* Constructs a React root ID
222
+ * @param {number} index A unique integer
223
* @return {string} A React root ID.
224
*/
226
- createReactRootID: function() {
227
- return getReactRootIDString(ReactRootIndex.createReactRootIndex());
225
+ createReactRootID: function(index) {
226
+ return getReactRootIDString(index);
227
},
228
229
/**
src/renderers/shared/reconciler/ReactRootIndex.js
deleted
-29
@@ -1,29 +0,0 @@
1
-/**
2
- * Copyright 2013-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 ReactRootIndex
10
- * @typechecks
11
- */
12
-
13
-'use strict';
14
-
15
-var ReactRootIndexInjection = {
16
- /**
17
- * @param {function} _createReactRootIndex
18
- */
19
- injectCreateReactRootIndex: function(_createReactRootIndex) {
20
- ReactRootIndex.createReactRootIndex = _createReactRootIndex;
21
- },
22
-};
23
-
24
-var ReactRootIndex = {
25
- createReactRootIndex: null,
26
- injection: ReactRootIndexInjection,
27
-};
28
-
29
-module.exports = ReactRootIndex;
src/test/ReactTestUtils.js
+4
-1
@@ -11,6 +11,7 @@
11
12
'use strict';
13
14
+var ClientReactRootIndex = require('ClientReactRootIndex');
15
var EventConstants = require('EventConstants');
16
var EventPluginHub = require('EventPluginHub');
17
var EventPropagators = require('EventPropagators');
@@ -425,7 +426,9 @@ ReactShallowRenderer.prototype._render = function(element, transaction, context)
426
if (this._instance) {
427
this._instance.receiveComponent(element, transaction, context);
428
} else {
428
- var rootID = ReactInstanceHandles.createReactRootID();
429
+ var rootID = ReactInstanceHandles.createReactRootID(
430
+ ClientReactRootIndex.createReactRootIndex()
431
+ );
432
var instance = new ShallowComponentWrapper(element.type);
433
instance.construct(element);
434