Skip to content

Commit

Permalink
Remove disableNewFiberFeatures flag (#10585)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Sep 1, 2017
1 parent edc9c2f commit de05d2e
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 378 deletions.
6 changes: 0 additions & 6 deletions src/isomorphic/children/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
describe('ReactChildren', () => {
var React;
var ReactTestUtils;
var ReactFeatureFlags;

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

if (ReactDOMFeatureFlags.useFiber) {
describe('with fragments enabled', () => {
beforeEach(() => {
ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = false;
});

it('warns for keys for arrays of elements in a fragment', () => {
spyOn(console, 'error');
class ComponentReturningArray extends React.Component {
Expand Down
4 changes: 0 additions & 4 deletions src/renderers/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ describe('ReactComponent', () => {

if (ReactDOMFeatureFlags.useFiber) {
describe('with new features', () => {
beforeEach(() => {
require('ReactFeatureFlags').disableNewFiberFeatures = false;
});

it('warns on function as a return value from a function', () => {
function Foo() {
return Foo;
Expand Down
49 changes: 22 additions & 27 deletions src/renderers/__tests__/ReactEmptyComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

var React;
var ReactDOM;
var ReactDOMFeatureFlags;
var ReactTestUtils;
var TogglingComponent;

var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');

var log;

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

React = require('react');
ReactDOM = require('react-dom');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
ReactTestUtils = require('react-dom/test-utils');

log = jasmine.createSpy();
Expand Down Expand Up @@ -71,18 +71,20 @@ describe('ReactEmptyComponent', () => {
expect(container2.children.length).toBe(0);
});

it('should still throw when rendering to undefined', () => {
class Component extends React.Component {
render() {}
}
if (ReactDOMFeatureFlags.useFiber) {
it('should still throw when rendering to undefined', () => {
class Component extends React.Component {
render() {}
}

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

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

it('can render null at the top level', () => {
var ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = false;
var div = document.createElement('div');

try {
if (ReactDOMFeatureFlags.useFiber) {
if (ReactDOMFeatureFlags.useFiber) {
ReactDOM.render(null, div);
expect(div.innerHTML).toBe('');
} else {
// Stack does not implement this.
expect(function() {
ReactDOM.render(null, div);
expect(div.innerHTML).toBe('');
} else {
// Stack does not implement this.
expect(function() {
ReactDOM.render(null, div);
}).toThrowError('ReactDOM.render(): Invalid component element.');
}
} finally {
ReactFeatureFlags.disableNewFiberFeatures = true;
}).toThrowError('ReactDOM.render(): Invalid component element.');
}
});

Expand Down
20 changes: 11 additions & 9 deletions src/renderers/__tests__/ReactStatelessComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ describe('ReactStatelessComponent', () => {
});
}

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

it('should throw on string refs in pure functions', () => {
function Child() {
Expand Down
5 changes: 0 additions & 5 deletions src/renderers/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,6 @@ describe('string refs between fiber and stack', () => {
});

describe('root level refs', () => {
beforeEach(() => {
var ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = false;
});

it('attaches and detaches root refs', () => {
var ReactDOM = require('react-dom');
var inst = null;
Expand Down
18 changes: 0 additions & 18 deletions src/renderers/dom/ReactDOMNodeStreamRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

'use strict';

var invariant = require('fbjs/lib/invariant');
var React = require('react');
var ReactPartialRenderer = require('ReactPartialRenderer');
var ReactFeatureFlags = require('ReactFeatureFlags');

var Readable = require('stream').Readable;

// This is a Readable Node.js stream which wraps the ReactDOMPartialRenderer.
Expand All @@ -41,13 +37,6 @@ class ReactMarkupReadableStream extends Readable {
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertonodestream
*/
function renderToNodeStream(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToNodeStream(): Invalid component element.',
);
}
return new ReactMarkupReadableStream(element, false);
}

Expand All @@ -57,13 +46,6 @@ function renderToNodeStream(element) {
* See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostaticnodestream
*/
function renderToStaticNodeStream(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToStaticNodeStream(): Invalid component element.',
);
}
return new ReactMarkupReadableStream(element, true);
}

Expand Down
17 changes: 0 additions & 17 deletions src/renderers/dom/ReactDOMStringRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,14 @@

'use strict';

var invariant = require('fbjs/lib/invariant');
var React = require('react');
var ReactPartialRenderer = require('ReactPartialRenderer');
var ReactFeatureFlags = require('ReactFeatureFlags');

/**
* Render a ReactElement to its initial HTML. This should only be used on the
* server.
* See https://facebook.github.io/react/docs/react-dom-server.html#rendertostring
*/
function renderToString(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToString(): Invalid component element.',
);
}
var renderer = new ReactPartialRenderer(element, false);
var markup = renderer.read(Infinity);
return markup;
Expand All @@ -40,13 +30,6 @@ function renderToString(element) {
* See https://facebook.github.io/react/docs/react-dom-server.html#rendertostaticmarkup
*/
function renderToStaticMarkup(element) {
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToStaticMarkup(): Invalid component element.',
);
}
var renderer = new ReactPartialRenderer(element, true);
var markup = renderer.read(Infinity);
return markup;
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/dom/__tests__/ReactDOMProduction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ describe('ReactDOMProduction', () => {
});

it('should throw with an error code in production', () => {
const errorCode = ReactDOMFeatureFlags.useFiber ? 152 : 109;
expect(function() {
class Component extends React.Component {
render() {
Expand All @@ -207,8 +208,8 @@ describe('ReactDOMProduction', () => {
var container = document.createElement('div');
ReactDOM.render(<Component />, container);
}).toThrowError(
'Minified React error #109; visit ' +
'http://facebook.github.io/react/docs/error-decoder.html?invariant=109&args[]=Component' +
`Minified React error #${errorCode}; visit ` +
`http://facebook.github.io/react/docs/error-decoder.html?invariant=${errorCode}&args[]=Component` +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
Expand Down
34 changes: 0 additions & 34 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
var ReactControlledComponent = require('ReactControlledComponent');
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactFeatureFlags = require('ReactFeatureFlags');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactDOMFiberComponent = require('ReactDOMFiberComponent');
var ReactDOMFrameScheduling = require('ReactDOMFrameScheduling');
Expand All @@ -31,7 +30,6 @@ var ReactInputSelection = require('ReactInputSelection');
var ReactInstanceMap = require('ReactInstanceMap');
var ReactPortal = require('ReactPortal');
var ReactVersion = require('ReactVersion');
var {isValidElement} = require('react');
var {injectInternals} = require('ReactFiberDevToolsHook');
var {
ELEMENT_NODE,
Expand Down Expand Up @@ -659,38 +657,6 @@ var ReactDOMFiber = {
container: DOMContainer,
callback: ?Function,
) {
if (ReactFeatureFlags.disableNewFiberFeatures) {
// Top-level check occurs here instead of inside child reconciler
// because requirements vary between renderers. E.g. React Art
// allows arrays.
if (!isValidElement(element)) {
if (typeof element === 'string') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
"passing a string like 'div', pass " +
"React.createElement('div') or <div />.",
);
} else if (typeof element === 'function') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a class like Foo, pass React.createElement(Foo) ' +
'or <Foo />.',
);
} else if (element != null && typeof element.props !== 'undefined') {
// Check if it quacks like an element
invariant(
false,
'ReactDOM.render(): Invalid component element. This may be ' +
'caused by unintentionally loading two independent copies ' +
'of React.',
);
} else {
invariant(false, 'ReactDOM.render(): Invalid component element.');
}
}
}
return renderSubtreeIntoContainer(
null,
element,
Expand Down
73 changes: 0 additions & 73 deletions src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ describe('ReactDOMFiber', () => {
}

var container;
var ReactFeatureFlags;

beforeEach(() => {
container = document.createElement('div');
ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = false;
});

afterEach(() => {
ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = true;
});

it('should render strings as children', () => {
Expand Down Expand Up @@ -1103,68 +1095,3 @@ describe('ReactDOMFiber', () => {
});
}
});

// disableNewFiberFeatures currently defaults to true in test
describe('disableNewFiberFeatures', () => {
var container;
var ReactFeatureFlags;

beforeEach(() => {
container = document.createElement('div');
ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = true;
});

afterEach(() => {
ReactFeatureFlags = require('ReactFeatureFlags');
ReactFeatureFlags.disableNewFiberFeatures = false;
});

it('throws if non-element passed to top-level render', () => {
const message = 'render(): Invalid component element.';
expect(() => ReactDOM.render(null, container)).toThrow(message, container);
expect(() => ReactDOM.render(undefined, container)).toThrow(
message,
container,
);
expect(() => ReactDOM.render(false, container)).toThrow(message, container);
expect(() => ReactDOM.render('Hi', container)).toThrow(message, container);
expect(() => ReactDOM.render(999, container)).toThrow(message, container);
expect(() => ReactDOM.render([<div key="a" />], container)).toThrow(
message,
container,
);
});

it('throws if something other than false, null, or an element is returned from render', () => {
function Render(props) {
return props.children;
}

expect(() => ReactDOM.render(<Render>Hi</Render>, container)).toThrow(
/You may have returned undefined/,
);
expect(() => ReactDOM.render(<Render>{999}</Render>, container)).toThrow(
/You may have returned undefined/,
);
expect(() =>
ReactDOM.render(<Render>[<div key="a" />]</Render>, container),
).toThrow(/You may have returned undefined/);
});

it('treats mocked render functions as if they return null', () => {
class Mocked extends React.Component {}
Mocked.prototype.render = jest.fn();
ReactDOM.render(<Mocked />, container);
expect(container.textContent).toEqual('');
});

it('throws if the React package cannot be loaded', () => {
jest.resetModules();
jest.mock('react', () => undefined);
expect(() => require('react-dom')).toThrow(
'ReactDOM was loaded before React.',
);
jest.resetModules();
});
});
Loading

0 comments on commit de05d2e

Please sign in to comment.