@samitouri / QOS-React / commits / bc2702f8bd

Fix Fiber devtools prod (#9019)

Ben Alpert committed Feb 16, 2017 at 18:00 UTC bc2702f8bd89737898874e05adc67a4b4f542929
4 files changed +45 -12
scripts/fiber/tests-passing.txt
+1
@@ -865,6 +865,7 @@ src/renderers/dom/__tests__/ReactDOMProduction-test.js
865 * should handle a simple flow
866 * should call lifecycle methods
867 * should throw with an error code in production
868 +* should not crash with devtools installed
869 * should keep track of namespace across portals in production
870
871 src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js
+10 -4
@@ -16,11 +16,18 @@ describe('ReactPropTypesProduction', function() {
16 var React;
17 var ReactPropTypeLocations;
18 var ReactTestUtils;
19 + var oldProcess;
20
21 beforeEach(function() {
22 __DEV__ = false;
22 - // eslint-disable-next-line dot-notation
23 - process.env['NODE_ENV'] = 'production';
23 +
24 + // Mutating process.env.NODE_ENV would cause our babel plugins to do the
25 + // wrong thing. If you change this, make sure to test with jest --no-cache.
26 + oldProcess = process;
27 + global.process = {
28 + ...process,
29 + env: {...process.env, NODE_ENV: 'production'},
30 + };
31
32 jest.resetModules();
33 PropTypes = require('ReactPropTypes');
@@ -31,8 +38,7 @@ describe('ReactPropTypesProduction', function() {
38
39 afterEach(function() {
40 __DEV__ = true;
34 - // eslint-disable-next-line dot-notation
35 - process.env['NODE_ENV'] = 'test';
41 + global.process = oldProcess;
42 });
43
44 function expectThrowsInProduction(declaration, value) {
src/renderers/dom/__tests__/ReactDOMProduction-test.js
+32 -4
@@ -15,11 +15,18 @@ describe('ReactDOMProduction', () => {
15
16 var React;
17 var ReactDOM;
18 + var oldProcess;
19
20 beforeEach(() => {
21 __DEV__ = false;
21 - // eslint-disable-next-line dot-notation
22 - process.env['NODE_ENV'] = 'production';
22 +
23 + // Mutating process.env.NODE_ENV would cause our babel plugins to do the
24 + // wrong thing. If you change this, make sure to test with jest --no-cache.
25 + oldProcess = process;
26 + global.process = {
27 + ...process,
28 + env: {...process.env, NODE_ENV: 'production'},
29 + };
30
31 jest.resetModules();
32 React = require('React');
@@ -28,8 +35,7 @@ describe('ReactDOMProduction', () => {
35
36 afterEach(() => {
37 __DEV__ = true;
31 - // eslint-disable-next-line dot-notation
32 - process.env['NODE_ENV'] = 'test';
38 + global.process = oldProcess;
39 });
40
41 it('should use prod fbjs', () => {
@@ -193,6 +199,28 @@ describe('ReactDOMProduction', () => {
199 );
200 });
201
202 + it('should not crash with devtools installed', () => {
203 + try {
204 + global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
205 + inject: function() {},
206 + onCommitFiberRoot: function() {},
207 + onCommitFiberUnmount: function() {},
208 + supportsFiber: true,
209 + };
210 + jest.resetModules();
211 + React = require('React');
212 + ReactDOM = require('ReactDOM');
213 + class Component extends React.Component {
214 + render() {
215 + return <div />;
216 + }
217 + }
218 + ReactDOM.render(<Component />, document.createElement('container'));
219 + } finally {
220 + global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = undefined;
221 + }
222 + });
223 +
224 if (ReactDOMFeatureFlags.useFiber) {
225 // This test is originally from ReactDOMFiber-test but we replicate it here
226 // to avoid production-only regressions because of host context differences
src/renderers/shared/fiber/ReactFiberDevToolsHook.js
+2 -4
@@ -12,15 +12,13 @@
12
13 'use strict';
14
15 +var warning = require('warning');
16 +
17 import type { Fiber } from 'ReactFiber';
18 import type { FiberRoot } from 'ReactFiberRoot';
19
20 declare var __REACT_DEVTOOLS_GLOBAL_HOOK__ : Object | void;
21
20 -if (__DEV__) {
21 - var warning = require('warning');
22 -}
23 -
22 let rendererID = null;
23 let injectInternals = null;
24 let onCommitRoot = null;