Skip to content

Commit 8fe6b5f

Browse files
authored
Inline dev-only requires (#7188)
* Inline dev-only requires This reduces the production bundled build size. * Use new references after resetting module registry in tests This fixes the tests which were broken due to inlining some requires.
1 parent 07cfba1 commit 8fe6b5f

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

src/isomorphic/classic/types/checkReactTypeSpec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
'use strict';
1313

14-
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
1514
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
1615

1716
var invariant = require('invariant');
@@ -72,10 +71,13 @@ function checkReactTypeSpec(typeSpecs, values, location, componentName, element,
7271

7372
var componentStackInfo = '';
7473

75-
if (debugID !== null) {
76-
componentStackInfo = ReactComponentTreeDevtool.getStackAddendumByID(debugID);
77-
} else if (element !== null) {
78-
componentStackInfo = ReactComponentTreeDevtool.getCurrentStackAddendum(element);
74+
if (__DEV__) {
75+
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
76+
if (debugID !== null) {
77+
componentStackInfo = ReactComponentTreeDevtool.getStackAddendumByID(debugID);
78+
} else if (element !== null) {
79+
componentStackInfo = ReactComponentTreeDevtool.getCurrentStackAddendum(element);
80+
}
7981
}
8082

8183
warning(

src/renderers/dom/shared/ReactDOMDebugTool.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
'use strict';
1313

14-
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
15-
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
1614
var ReactDebugTool = require('ReactDebugTool');
1715

1816
var warning = require('warning');
@@ -68,7 +66,11 @@ var ReactDOMDebugTool = {
6866
},
6967
};
7068

71-
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
72-
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
69+
if (__DEV__) {
70+
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
71+
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
72+
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
73+
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
74+
}
7375

7476
module.exports = ReactDOMDebugTool;

src/renderers/shared/stack/reconciler/ReactChildReconciler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
var ReactReconciler = require('ReactReconciler');
1515

16-
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
1716
var instantiateReactComponent = require('instantiateReactComponent');
1817
var KeyEscapeUtils = require('KeyEscapeUtils');
1918
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
@@ -24,6 +23,7 @@ function instantiateChild(childInstances, child, name, selfDebugID) {
2423
// We found a component instance.
2524
var keyUnique = (childInstances[name] === undefined);
2625
if (__DEV__) {
26+
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
2727
warning(
2828
keyUnique,
2929
'flattenChildren(...): Encountered two children with the same key, ' +

src/renderers/shared/stack/reconciler/__tests__/ReactMultiChildReconcile-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ function testPropsSequence(sequence) {
278278
describe('ReactMultiChildReconcile', function() {
279279
beforeEach(function() {
280280
jest.resetModuleRegistry();
281+
282+
React = require('React');
283+
ReactDOM = require('ReactDOM');
284+
ReactDOMComponentTree = require('ReactDOMComponentTree');
285+
ReactInstanceMap = require('ReactInstanceMap');
286+
mapObject = require('mapObject');
281287
});
282288

283289
it('should reset internal state if removed then readded', function() {

src/renderers/shared/stack/reconciler/__tests__/refs-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ var expectClickLogsLengthToBe = function(instance, length) {
116116
describe('reactiverefs', function() {
117117
beforeEach(function() {
118118
jest.resetModuleRegistry();
119+
120+
React = require('React');
121+
ReactTestUtils = require('ReactTestUtils');
122+
reactComponentExpect = require('reactComponentExpect');
119123
});
120124

121125
/**
@@ -159,6 +163,10 @@ describe('reactiverefs', function() {
159163
describe('ref swapping', function() {
160164
beforeEach(function() {
161165
jest.resetModuleRegistry();
166+
167+
React = require('React');
168+
ReactTestUtils = require('ReactTestUtils');
169+
reactComponentExpect = require('reactComponentExpect');
162170
});
163171

164172
var RefHopsAround = React.createClass({
@@ -275,4 +283,3 @@ describe('ref swapping', function() {
275283
__DEV__ = originalDev;
276284
});
277285
});
278-

src/shared/utils/flattenChildren.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
'use strict';
1414

15-
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
1615
var KeyEscapeUtils = require('KeyEscapeUtils');
1716
var traverseAllChildren = require('traverseAllChildren');
1817
var warning = require('warning');
@@ -34,6 +33,7 @@ function flattenSingleChildIntoContext(
3433
const result = traverseContext;
3534
const keyUnique = (result[name] === undefined);
3635
if (__DEV__) {
36+
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
3737
warning(
3838
keyUnique,
3939
'flattenChildren(...): Encountered two children with the same key, ' +

0 commit comments

Comments
 (0)