Skip to content

Commit de05d2e

Browse files
authored
Remove disableNewFiberFeatures flag (#10585)
1 parent edc9c2f commit de05d2e

27 files changed

+92
-378
lines changed

src/isomorphic/children/__tests__/ReactChildren-test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
1616
describe('ReactChildren', () => {
1717
var React;
1818
var ReactTestUtils;
19-
var ReactFeatureFlags;
2019

2120
function normalizeCodeLocInfo(str) {
2221
return str && str.replace(/at .+?:\d+/g, 'at **');
@@ -883,11 +882,6 @@ describe('ReactChildren', () => {
883882

884883
if (ReactDOMFeatureFlags.useFiber) {
885884
describe('with fragments enabled', () => {
886-
beforeEach(() => {
887-
ReactFeatureFlags = require('ReactFeatureFlags');
888-
ReactFeatureFlags.disableNewFiberFeatures = false;
889-
});
890-
891885
it('warns for keys for arrays of elements in a fragment', () => {
892886
spyOn(console, 'error');
893887
class ComponentReturningArray extends React.Component {

src/renderers/__tests__/ReactComponent-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,6 @@ describe('ReactComponent', () => {
496496

497497
if (ReactDOMFeatureFlags.useFiber) {
498498
describe('with new features', () => {
499-
beforeEach(() => {
500-
require('ReactFeatureFlags').disableNewFiberFeatures = false;
501-
});
502-
503499
it('warns on function as a return value from a function', () => {
504500
function Foo() {
505501
return Foo;

src/renderers/__tests__/ReactEmptyComponent-test.js

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
var React;
1515
var ReactDOM;
16-
var ReactDOMFeatureFlags;
1716
var ReactTestUtils;
1817
var TogglingComponent;
1918

19+
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
20+
2021
var log;
2122

2223
describe('ReactEmptyComponent', () => {
@@ -25,7 +26,6 @@ describe('ReactEmptyComponent', () => {
2526

2627
React = require('react');
2728
ReactDOM = require('react-dom');
28-
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
2929
ReactTestUtils = require('react-dom/test-utils');
3030

3131
log = jasmine.createSpy();
@@ -71,18 +71,20 @@ describe('ReactEmptyComponent', () => {
7171
expect(container2.children.length).toBe(0);
7272
});
7373

74-
it('should still throw when rendering to undefined', () => {
75-
class Component extends React.Component {
76-
render() {}
77-
}
74+
if (ReactDOMFeatureFlags.useFiber) {
75+
it('should still throw when rendering to undefined', () => {
76+
class Component extends React.Component {
77+
render() {}
78+
}
7879

79-
expect(function() {
80-
ReactTestUtils.renderIntoDocument(<Component />);
81-
}).toThrowError(
82-
'Component.render(): A valid React element (or null) must be returned. You may ' +
83-
'have returned undefined, an array or some other invalid object.',
84-
);
85-
});
80+
expect(function() {
81+
ReactTestUtils.renderIntoDocument(<Component />);
82+
}).toThrowError(
83+
'Component(...): Nothing was returned from render. This usually means a return statement is missing. ' +
84+
'Or, to render nothing, return null.',
85+
);
86+
});
87+
}
8688

8789
it('should be able to switch between rendering null and a normal tag', () => {
8890
var instance1 = (
@@ -232,22 +234,15 @@ describe('ReactEmptyComponent', () => {
232234
});
233235

234236
it('can render null at the top level', () => {
235-
var ReactFeatureFlags = require('ReactFeatureFlags');
236-
ReactFeatureFlags.disableNewFiberFeatures = false;
237237
var div = document.createElement('div');
238-
239-
try {
240-
if (ReactDOMFeatureFlags.useFiber) {
238+
if (ReactDOMFeatureFlags.useFiber) {
239+
ReactDOM.render(null, div);
240+
expect(div.innerHTML).toBe('');
241+
} else {
242+
// Stack does not implement this.
243+
expect(function() {
241244
ReactDOM.render(null, div);
242-
expect(div.innerHTML).toBe('');
243-
} else {
244-
// Stack does not implement this.
245-
expect(function() {
246-
ReactDOM.render(null, div);
247-
}).toThrowError('ReactDOM.render(): Invalid component element.');
248-
}
249-
} finally {
250-
ReactFeatureFlags.disableNewFiberFeatures = true;
245+
}).toThrowError('ReactDOM.render(): Invalid component element.');
251246
}
252247
});
253248

src/renderers/__tests__/ReactStatelessComponent-test.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ describe('ReactStatelessComponent', () => {
157157
});
158158
}
159159

160-
it('should throw when stateless component returns undefined', () => {
161-
function NotAComponent() {}
162-
expect(function() {
163-
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
164-
}).toThrowError(
165-
'NotAComponent(...): A valid React element (or null) must be returned. ' +
166-
'You may have returned undefined, an array or some other invalid object.',
167-
);
168-
});
160+
if (ReactDOMFeatureFlags.useFiber) {
161+
it('should throw when stateless component returns undefined', () => {
162+
function NotAComponent() {}
163+
expect(function() {
164+
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
165+
}).toThrowError(
166+
'NotAComponent(...): Nothing was returned from render. ' +
167+
'This usually means a return statement is missing. Or, to render nothing, return null.',
168+
);
169+
});
170+
}
169171

170172
it('should throw on string refs in pure functions', () => {
171173
function Child() {

src/renderers/__tests__/refs-test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,6 @@ describe('string refs between fiber and stack', () => {
394394
});
395395

396396
describe('root level refs', () => {
397-
beforeEach(() => {
398-
var ReactFeatureFlags = require('ReactFeatureFlags');
399-
ReactFeatureFlags.disableNewFiberFeatures = false;
400-
});
401-
402397
it('attaches and detaches root refs', () => {
403398
var ReactDOM = require('react-dom');
404399
var inst = null;

src/renderers/dom/ReactDOMNodeStreamRenderer.js

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

1212
'use strict';
1313

14-
var invariant = require('fbjs/lib/invariant');
15-
var React = require('react');
1614
var ReactPartialRenderer = require('ReactPartialRenderer');
17-
var ReactFeatureFlags = require('ReactFeatureFlags');
18-
1915
var Readable = require('stream').Readable;
2016

2117
// This is a Readable Node.js stream which wraps the ReactDOMPartialRenderer.
@@ -41,13 +37,6 @@ class ReactMarkupReadableStream extends Readable {
4137
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertonodestream
4238
*/
4339
function renderToNodeStream(element) {
44-
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
45-
if (disableNewFiberFeatures) {
46-
invariant(
47-
React.isValidElement(element),
48-
'renderToNodeStream(): Invalid component element.',
49-
);
50-
}
5140
return new ReactMarkupReadableStream(element, false);
5241
}
5342

@@ -57,13 +46,6 @@ function renderToNodeStream(element) {
5746
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostaticnodestream
5847
*/
5948
function renderToStaticNodeStream(element) {
60-
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
61-
if (disableNewFiberFeatures) {
62-
invariant(
63-
React.isValidElement(element),
64-
'renderToStaticNodeStream(): Invalid component element.',
65-
);
66-
}
6749
return new ReactMarkupReadableStream(element, true);
6850
}
6951

src/renderers/dom/ReactDOMStringRenderer.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,14 @@
1111

1212
'use strict';
1313

14-
var invariant = require('fbjs/lib/invariant');
15-
var React = require('react');
1614
var ReactPartialRenderer = require('ReactPartialRenderer');
17-
var ReactFeatureFlags = require('ReactFeatureFlags');
1815

1916
/**
2017
* Render a ReactElement to its initial HTML. This should only be used on the
2118
* server.
2219
* See https://facebook.github.io/react/docs/react-dom-server.html#rendertostring
2320
*/
2421
function renderToString(element) {
25-
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
26-
if (disableNewFiberFeatures) {
27-
invariant(
28-
React.isValidElement(element),
29-
'renderToString(): Invalid component element.',
30-
);
31-
}
3222
var renderer = new ReactPartialRenderer(element, false);
3323
var markup = renderer.read(Infinity);
3424
return markup;
@@ -40,13 +30,6 @@ function renderToString(element) {
4030
* See https://facebook.github.io/react/docs/react-dom-server.html#rendertostaticmarkup
4131
*/
4232
function renderToStaticMarkup(element) {
43-
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
44-
if (disableNewFiberFeatures) {
45-
invariant(
46-
React.isValidElement(element),
47-
'renderToStaticMarkup(): Invalid component element.',
48-
);
49-
}
5033
var renderer = new ReactPartialRenderer(element, true);
5134
var markup = renderer.read(Infinity);
5235
return markup;

src/renderers/dom/__tests__/ReactDOMProduction-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ describe('ReactDOMProduction', () => {
197197
});
198198

199199
it('should throw with an error code in production', () => {
200+
const errorCode = ReactDOMFeatureFlags.useFiber ? 152 : 109;
200201
expect(function() {
201202
class Component extends React.Component {
202203
render() {
@@ -207,8 +208,8 @@ describe('ReactDOMProduction', () => {
207208
var container = document.createElement('div');
208209
ReactDOM.render(<Component />, container);
209210
}).toThrowError(
210-
'Minified React error #109; visit ' +
211-
'http://facebook.github.io/react/docs/error-decoder.html?invariant=109&args[]=Component' +
211+
`Minified React error #${errorCode}; visit ` +
212+
`http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=Component` +
212213
' for the full message or use the non-minified dev environment' +
213214
' for full errors and additional helpful warnings.',
214215
);

src/renderers/dom/fiber/ReactDOMFiberEntry.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
2121
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
2222
var ReactControlledComponent = require('ReactControlledComponent');
2323
var ReactDOMComponentTree = require('ReactDOMComponentTree');
24-
var ReactFeatureFlags = require('ReactFeatureFlags');
2524
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
2625
var ReactDOMFiberComponent = require('ReactDOMFiberComponent');
2726
var ReactDOMFrameScheduling = require('ReactDOMFrameScheduling');
@@ -31,7 +30,6 @@ var ReactInputSelection = require('ReactInputSelection');
3130
var ReactInstanceMap = require('ReactInstanceMap');
3231
var ReactPortal = require('ReactPortal');
3332
var ReactVersion = require('ReactVersion');
34-
var {isValidElement} = require('react');
3533
var {injectInternals} = require('ReactFiberDevToolsHook');
3634
var {
3735
ELEMENT_NODE,
@@ -659,38 +657,6 @@ var ReactDOMFiber = {
659657
container: DOMContainer,
660658
callback: ?Function,
661659
) {
662-
if (ReactFeatureFlags.disableNewFiberFeatures) {
663-
// Top-level check occurs here instead of inside child reconciler
664-
// because requirements vary between renderers. E.g. React Art
665-
// allows arrays.
666-
if (!isValidElement(element)) {
667-
if (typeof element === 'string') {
668-
invariant(
669-
false,
670-
'ReactDOM.render(): Invalid component element. Instead of ' +
671-
"passing a string like 'div', pass " +
672-
"React.createElement('div') or <div />.",
673-
);
674-
} else if (typeof element === 'function') {
675-
invariant(
676-
false,
677-
'ReactDOM.render(): Invalid component element. Instead of ' +
678-
'passing a class like Foo, pass React.createElement(Foo) ' +
679-
'or <Foo />.',
680-
);
681-
} else if (element != null && typeof element.props !== 'undefined') {
682-
// Check if it quacks like an element
683-
invariant(
684-
false,
685-
'ReactDOM.render(): Invalid component element. This may be ' +
686-
'caused by unintentionally loading two independent copies ' +
687-
'of React.',
688-
);
689-
} else {
690-
invariant(false, 'ReactDOM.render(): Invalid component element.');
691-
}
692-
}
693-
}
694660
return renderSubtreeIntoContainer(
695661
null,
696662
element,

src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ describe('ReactDOMFiber', () => {
2323
}
2424

2525
var container;
26-
var ReactFeatureFlags;
2726

2827
beforeEach(() => {
2928
container = document.createElement('div');
30-
ReactFeatureFlags = require('ReactFeatureFlags');
31-
ReactFeatureFlags.disableNewFiberFeatures = false;
32-
});
33-
34-
afterEach(() => {
35-
ReactFeatureFlags = require('ReactFeatureFlags');
36-
ReactFeatureFlags.disableNewFiberFeatures = true;
3729
});
3830

3931
it('should render strings as children', () => {
@@ -1103,68 +1095,3 @@ describe('ReactDOMFiber', () => {
11031095
});
11041096
}
11051097
});
1106-
1107-
// disableNewFiberFeatures currently defaults to true in test
1108-
describe('disableNewFiberFeatures', () => {
1109-
var container;
1110-
var ReactFeatureFlags;
1111-
1112-
beforeEach(() => {
1113-
container = document.createElement('div');
1114-
ReactFeatureFlags = require('ReactFeatureFlags');
1115-
ReactFeatureFlags.disableNewFiberFeatures = true;
1116-
});
1117-
1118-
afterEach(() => {
1119-
ReactFeatureFlags = require('ReactFeatureFlags');
1120-
ReactFeatureFlags.disableNewFiberFeatures = false;
1121-
});
1122-
1123-
it('throws if non-element passed to top-level render', () => {
1124-
const message = 'render(): Invalid component element.';
1125-
expect(() => ReactDOM.render(null, container)).toThrow(message, container);
1126-
expect(() => ReactDOM.render(undefined, container)).toThrow(
1127-
message,
1128-
container,
1129-
);
1130-
expect(() => ReactDOM.render(false, container)).toThrow(message, container);
1131-
expect(() => ReactDOM.render('Hi', container)).toThrow(message, container);
1132-
expect(() => ReactDOM.render(999, container)).toThrow(message, container);
1133-
expect(() => ReactDOM.render([<div key="a" />], container)).toThrow(
1134-
message,
1135-
container,
1136-
);
1137-
});
1138-
1139-
it('throws if something other than false, null, or an element is returned from render', () => {
1140-
function Render(props) {
1141-
return props.children;
1142-
}
1143-
1144-
expect(() => ReactDOM.render(<Render>Hi</Render>, container)).toThrow(
1145-
/You may have returned undefined/,
1146-
);
1147-
expect(() => ReactDOM.render(<Render>{999}</Render>, container)).toThrow(
1148-
/You may have returned undefined/,
1149-
);
1150-
expect(() =>
1151-
ReactDOM.render(<Render>[<div key="a" />]</Render>, container),
1152-
).toThrow(/You may have returned undefined/);
1153-
});
1154-
1155-
it('treats mocked render functions as if they return null', () => {
1156-
class Mocked extends React.Component {}
1157-
Mocked.prototype.render = jest.fn();
1158-
ReactDOM.render(<Mocked />, container);
1159-
expect(container.textContent).toEqual('');
1160-
});
1161-
1162-
it('throws if the React package cannot be loaded', () => {
1163-
jest.resetModules();
1164-
jest.mock('react', () => undefined);
1165-
expect(() => require('react-dom')).toThrow(
1166-
'ReactDOM was loaded before React.',
1167-
);
1168-
jest.resetModules();
1169-
});
1170-
});

0 commit comments

Comments
 (0)