Skip to content

Commit

Permalink
Inline dev-only requires (#7188)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
gaearon committed Jul 5, 2016
1 parent 07cfba1 commit 8fe6b5f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/isomorphic/classic/types/checkReactTypeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

'use strict';

var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');

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

var componentStackInfo = '';

if (debugID !== null) {
componentStackInfo = ReactComponentTreeDevtool.getStackAddendumByID(debugID);
} else if (element !== null) {
componentStackInfo = ReactComponentTreeDevtool.getCurrentStackAddendum(element);
if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
if (debugID !== null) {
componentStackInfo = ReactComponentTreeDevtool.getStackAddendumByID(debugID);
} else if (element !== null) {
componentStackInfo = ReactComponentTreeDevtool.getCurrentStackAddendum(element);
}
}

warning(
Expand Down
10 changes: 6 additions & 4 deletions src/renderers/dom/shared/ReactDOMDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

'use strict';

var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
var ReactDebugTool = require('ReactDebugTool');

var warning = require('warning');
Expand Down Expand Up @@ -68,7 +66,11 @@ var ReactDOMDebugTool = {
},
};

ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
if (__DEV__) {
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
}

module.exports = ReactDOMDebugTool;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

var ReactReconciler = require('ReactReconciler');

var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var instantiateReactComponent = require('instantiateReactComponent');
var KeyEscapeUtils = require('KeyEscapeUtils');
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
Expand All @@ -24,6 +23,7 @@ function instantiateChild(childInstances, child, name, selfDebugID) {
// We found a component instance.
var keyUnique = (childInstances[name] === undefined);
if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ function testPropsSequence(sequence) {
describe('ReactMultiChildReconcile', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactDOM = require('ReactDOM');
ReactDOMComponentTree = require('ReactDOMComponentTree');
ReactInstanceMap = require('ReactInstanceMap');
mapObject = require('mapObject');
});

it('should reset internal state if removed then readded', function() {
Expand Down
9 changes: 8 additions & 1 deletion src/renderers/shared/stack/reconciler/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ var expectClickLogsLengthToBe = function(instance, length) {
describe('reactiverefs', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactTestUtils = require('ReactTestUtils');
reactComponentExpect = require('reactComponentExpect');
});

/**
Expand Down Expand Up @@ -159,6 +163,10 @@ describe('reactiverefs', function() {
describe('ref swapping', function() {
beforeEach(function() {
jest.resetModuleRegistry();

React = require('React');
ReactTestUtils = require('ReactTestUtils');
reactComponentExpect = require('reactComponentExpect');
});

var RefHopsAround = React.createClass({
Expand Down Expand Up @@ -275,4 +283,3 @@ describe('ref swapping', function() {
__DEV__ = originalDev;
});
});

2 changes: 1 addition & 1 deletion src/shared/utils/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

'use strict';

var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var KeyEscapeUtils = require('KeyEscapeUtils');
var traverseAllChildren = require('traverseAllChildren');
var warning = require('warning');
Expand All @@ -34,6 +33,7 @@ function flattenSingleChildIntoContext(
const result = traverseContext;
const keyUnique = (result[name] === undefined);
if (__DEV__) {
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
Expand Down

0 comments on commit 8fe6b5f

Please sign in to comment.