diff --git a/packages/react-call-return/src/__tests__/ReactCallReturn-test.js b/packages/react-call-return/src/__tests__/ReactCallReturn-test.js index 74bbc1b6a1c38..8f783945aa24c 100644 --- a/packages/react-call-return/src/__tests__/ReactCallReturn-test.js +++ b/packages/react-call-return/src/__tests__/ReactCallReturn-test.js @@ -275,7 +275,7 @@ describe('ReactCallReturn', () => { return ReactCallReturn.unstable_createReturn(this.props.children); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push(`Mount Return ${this.props.value}`); } diff --git a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js index 792b1d3242fd9..d133868d21400 100644 --- a/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js +++ b/packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js @@ -165,7 +165,7 @@ describe('ReactComponentLifeCycle', () => { // had provided a getInitialState method. it('throws when accessing state in componentWillMount', () => { class StatefulComponent extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { void this.state.yada; } @@ -182,7 +182,7 @@ describe('ReactComponentLifeCycle', () => { it('should allow update state inside of componentWillMount', () => { class StatefulComponent extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({stateField: 'something'}); } @@ -231,7 +231,7 @@ describe('ReactComponentLifeCycle', () => { // reaching into the updater. return this.updater.isMounted(this); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { expect(this._isMounted()).toBeFalsy(); } componentDidMount() { @@ -258,7 +258,7 @@ describe('ReactComponentLifeCycle', () => { // reaching into the updater. return this.updater.isMounted(this); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { expect(this._isMounted()).toBeFalsy(); } componentDidMount() { @@ -334,7 +334,7 @@ describe('ReactComponentLifeCycle', () => { this.state = initState; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this._testJournal.stateAtStartOfWillMount = clone(this.state); this._testJournal.lifeCycleAtStartOfWillMount = getLifeCycleState(this); this.state.hasWillMountCompleted = true; @@ -509,13 +509,13 @@ describe('ReactComponentLifeCycle', () => { }; }; class Outer extends React.Component { - unsafe_componentWillMount = logger('outer componentWillMount'); + UNSAFE_componentWillMount = logger('outer componentWillMount'); componentDidMount = logger('outer componentDidMount'); - unsafe_componentWillReceiveProps = logger( + UNSAFE_componentWillReceiveProps = logger( 'outer componentWillReceiveProps', ); shouldComponentUpdate = logger('outer shouldComponentUpdate'); - unsafe_componentWillUpdate = logger('outer componentWillUpdate'); + UNSAFE_componentWillUpdate = logger('outer componentWillUpdate'); componentDidUpdate = logger('outer componentDidUpdate'); componentWillUnmount = logger('outer componentWillUnmount'); render() { @@ -528,13 +528,13 @@ describe('ReactComponentLifeCycle', () => { } class Inner extends React.Component { - unsafe_componentWillMount = logger('inner componentWillMount'); + UNSAFE_componentWillMount = logger('inner componentWillMount'); componentDidMount = logger('inner componentDidMount'); - unsafe_componentWillReceiveProps = logger( + UNSAFE_componentWillReceiveProps = logger( 'inner componentWillReceiveProps', ); shouldComponentUpdate = logger('inner shouldComponentUpdate'); - unsafe_componentWillUpdate = logger('inner componentWillUpdate'); + UNSAFE_componentWillUpdate = logger('inner componentWillUpdate'); componentDidUpdate = logger('inner componentDidUpdate'); componentWillUnmount = logger('inner componentWillUnmount'); render() { @@ -583,7 +583,7 @@ describe('ReactComponentLifeCycle', () => { log.push('render'); return ; }, - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('will mount'); }, componentDidMount() { diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index 905b84d0361bb..54649cc28f224 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -850,7 +850,7 @@ describe('ReactCompositeComponent', () => { foo: PropTypes.string.isRequired, }; - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { expect('foo' in nextContext).toBe(true); } @@ -865,7 +865,7 @@ describe('ReactCompositeComponent', () => { } class Intermediary extends React.Component { - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { expect('foo' in nextContext).toBe(false); } @@ -916,7 +916,7 @@ describe('ReactCompositeComponent', () => { foo: PropTypes.string.isRequired, }; - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { expect('foo' in nextContext).toBe(true); if (nextProps !== this.props) { @@ -938,7 +938,7 @@ describe('ReactCompositeComponent', () => { foo: PropTypes.string.isRequired, }; - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { expect('foo' in nextContext).toBe(true); if (nextProps !== this.props) { @@ -956,7 +956,7 @@ describe('ReactCompositeComponent', () => { } class ChildWithoutContext extends React.Component { - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { expect('foo' in nextContext).toBe(false); if (nextProps !== this.props) { @@ -1047,7 +1047,7 @@ describe('ReactCompositeComponent', () => { class Component extends React.Component { state = {updated: false}; - unsafe_componentWillReceiveProps(props) { + UNSAFE_componentWillReceiveProps(props) { expect(props.update).toBe(1); expect(renders).toBe(1); this.setState({updated: true}); @@ -1075,7 +1075,7 @@ describe('ReactCompositeComponent', () => { class Component extends React.Component { state = {updated: false}; - unsafe_componentWillReceiveProps(props) { + UNSAFE_componentWillReceiveProps(props) { expect(props.update).toBe(1); expect(renders).toBe(1); this.setState({updated: true}); @@ -1377,7 +1377,7 @@ describe('ReactCompositeComponent', () => { const log = []; class Spy extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push(this.props.name + ' componentWillMount'); } render() { @@ -1556,7 +1556,7 @@ describe('ReactCompositeComponent', () => { }; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState( {hasUpdatedState: true}, () => (stateSuccessfullyUpdated = this.state.hasUpdatedState), @@ -1586,7 +1586,7 @@ describe('ReactCompositeComponent', () => { }; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { instance = this; } diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js index 8fd6bb35259f1..83f9a7a5babb3 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponentState-test.js @@ -46,7 +46,7 @@ describe('ReactCompositeComponent-state', () => { return
{this.state.color}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.peekAtState('componentWillMount-start'); this.setState(function(state) { this.peekAtState('before-setState-sunrise', state); @@ -78,7 +78,7 @@ describe('ReactCompositeComponent-state', () => { this.peekAtState('componentDidMount-end'); } - unsafe_componentWillReceiveProps(newProps) { + UNSAFE_componentWillReceiveProps(newProps) { this.peekAtState('componentWillReceiveProps-start'); if (newProps.nextColor) { this.setState(function(state) { @@ -105,7 +105,7 @@ describe('ReactCompositeComponent-state', () => { return true; } - unsafe_componentWillUpdate(nextProps, nextState) { + UNSAFE_componentWillUpdate(nextProps, nextState) { this.peekAtState('componentWillUpdate-currentState'); this.peekAtState('componentWillUpdate-nextState', nextState); } @@ -323,7 +323,7 @@ describe('ReactCompositeComponent-state', () => { } let updated = false; class Child extends React.Component { - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { if (updated) { return; } @@ -383,7 +383,7 @@ describe('ReactCompositeComponent-state', () => { let ops = []; class Test extends React.Component { state = {step: 1, extra: true}; - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { this.setState({step: 2}, () => { // Tests that earlier setState callbacks are not dropped ops.push( @@ -426,7 +426,7 @@ describe('ReactCompositeComponent-state', () => { let ops = []; class Test extends React.Component { state = {step: 1, extra: true}; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({step: 2}, () => { // Tests that earlier setState callbacks are not dropped ops.push( diff --git a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationContext-test.js b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationContext-test.js index 52689530f1ccf..4ccf8a303c6ff 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerIntegrationContext-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerIntegrationContext-test.js @@ -231,7 +231,7 @@ describe('ReactDOMServerIntegration', () => { getChildContext() { return {text: this.state.text}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({text: 'foo'}); } render() { diff --git a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js index 620cb936d2885..db1bf292376ec 100644 --- a/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js @@ -37,7 +37,7 @@ describe('ReactDOMServerLifecycles', () => { const log = []; class Outer extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('outer componentWillMount'); } render() { @@ -47,7 +47,7 @@ describe('ReactDOMServerLifecycles', () => { } class Inner extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('inner componentWillMount'); } render() { @@ -75,7 +75,7 @@ describe('ReactDOMServerLifecycles', () => { expect(() => ReactDOMServer.renderToString()).toWarnDev( 'Warning: Component: componentWillMount() is deprecated and will be removed ' + - 'in the next major version. Please use unsafe_componentWillMount() instead.', + 'in the next major version. Please use UNSAFE_componentWillMount() instead.', ); // De-duped diff --git a/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.js b/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.js index b51e263242a08..42fc69cca00e1 100644 --- a/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.js +++ b/packages/react-dom/src/__tests__/ReactErrorBoundaries-test.js @@ -50,16 +50,16 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenConstructor render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenConstructor componentWillMount'); } componentDidMount() { log.push('BrokenConstructor componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenConstructor componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenConstructor componentWillUpdate'); } componentDidUpdate() { @@ -79,17 +79,17 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentWillMount render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentWillMount componentWillMount [!]'); throw new Error('Hello'); } componentDidMount() { log.push('BrokenComponentWillMount componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenComponentWillMount componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentWillMount componentWillUpdate'); } componentDidUpdate() { @@ -109,17 +109,17 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentDidMount render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentDidMount componentWillMount'); } componentDidMount() { log.push('BrokenComponentDidMount componentDidMount [!]'); throw new Error('Hello'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenComponentDidMount componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentDidMount componentWillUpdate'); } componentDidUpdate() { @@ -139,19 +139,19 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentWillReceiveProps render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentWillReceiveProps componentWillMount'); } componentDidMount() { log.push('BrokenComponentWillReceiveProps componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push( 'BrokenComponentWillReceiveProps componentWillReceiveProps [!]', ); throw new Error('Hello'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentWillReceiveProps componentWillUpdate'); } componentDidUpdate() { @@ -171,16 +171,16 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentWillUpdate render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentWillUpdate componentWillMount'); } componentDidMount() { log.push('BrokenComponentWillUpdate componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenComponentWillUpdate componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentWillUpdate componentWillUpdate [!]'); throw new Error('Hello'); } @@ -204,16 +204,16 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentDidUpdate render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentDidUpdate componentWillMount'); } componentDidMount() { log.push('BrokenComponentDidUpdate componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenComponentDidUpdate componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentDidUpdate componentWillUpdate'); } componentDidUpdate() { @@ -237,16 +237,16 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentWillUnmount render'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentWillUnmount componentWillMount'); } componentDidMount() { log.push('BrokenComponentWillUnmount componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenComponentWillUnmount componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenComponentWillUnmount componentWillUpdate'); } componentDidUpdate() { @@ -272,7 +272,7 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentWillMountErrorBoundary render success'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push( 'BrokenComponentWillMountErrorBoundary componentWillMount [!]', ); @@ -304,7 +304,7 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenComponentDidMountErrorBoundary render success'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenComponentDidMountErrorBoundary componentWillMount'); } componentDidMount() { @@ -334,7 +334,7 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenRenderErrorBoundary render success'); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenRenderErrorBoundary componentWillMount'); } componentDidMount() { @@ -358,16 +358,16 @@ describe('ReactErrorBoundaries', () => { log.push('BrokenRender render [!]'); throw new Error('Hello'); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('BrokenRender componentWillMount'); } componentDidMount() { log.push('BrokenRender componentDidMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('BrokenRender componentWillReceiveProps'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('BrokenRender componentWillUpdate'); } componentDidUpdate() { @@ -387,7 +387,7 @@ describe('ReactErrorBoundaries', () => { log.push('NoopErrorBoundary render'); return ; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('NoopErrorBoundary componentWillMount'); } componentDidMount() { @@ -413,16 +413,16 @@ describe('ReactErrorBoundaries', () => { log.push(`${this.props.logName} render`); return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push(`${this.props.logName} componentWillMount`); } componentDidMount() { log.push(`${this.props.logName} componentDidMount`); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push(`${this.props.logName} componentWillReceiveProps`); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push(`${this.props.logName} componentWillUpdate`); } componentDidUpdate() { @@ -451,16 +451,16 @@ describe('ReactErrorBoundaries', () => { log.push(`${this.props.logName} componentDidCatch`); this.setState({error}); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push(`${this.props.logName} componentWillMount`); } componentDidMount() { log.push(`${this.props.logName} componentDidMount`); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push(`${this.props.logName} componentWillReceiveProps`); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push(`${this.props.logName} componentWillUpdate`); } componentDidUpdate() { @@ -490,7 +490,7 @@ describe('ReactErrorBoundaries', () => { log.push('RetryErrorBoundary render'); return ; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('RetryErrorBoundary componentWillMount'); } componentDidMount() { @@ -511,7 +511,7 @@ describe('ReactErrorBoundaries', () => { super(props); log.push('ErrorMessage constructor'); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('ErrorMessage componentWillMount'); } componentDidMount() { @@ -703,7 +703,7 @@ describe('ReactErrorBoundaries', () => { render() { return
{this.props.children}
; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { throw new Error('Hello'); } } @@ -727,7 +727,7 @@ describe('ReactErrorBoundaries', () => { render() { return
{this.props.children}
; }, - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { throw new Error('Hello'); }, }; diff --git a/packages/react-dom/src/__tests__/ReactMultiChild-test.js b/packages/react-dom/src/__tests__/ReactMultiChild-test.js index a27b76b28f25b..78933828331df 100644 --- a/packages/react-dom/src/__tests__/ReactMultiChild-test.js +++ b/packages/react-dom/src/__tests__/ReactMultiChild-test.js @@ -330,7 +330,7 @@ describe('ReactMultiChild', () => { const log = []; class Spy extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push(this.props.name + ' componentWillMount'); } render() { diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js index aa6b1fbbe02a1..f37fa2c15cd6e 100644 --- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js +++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js @@ -98,7 +98,7 @@ describe('ReactDOMServer', () => { this.state = {name: 'TestComponent'}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { lifecycle.push('componentWillMount'); } @@ -111,7 +111,7 @@ describe('ReactDOMServer', () => { return Component name: {this.state.name}; } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { lifecycle.push('componentWillUpdate'); } @@ -123,7 +123,7 @@ describe('ReactDOMServer', () => { lifecycle.push('shouldComponentUpdate'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { lifecycle.push('componentWillReceiveProps'); } @@ -240,7 +240,7 @@ describe('ReactDOMServer', () => { this.state = {name: 'TestComponent'}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { lifecycle.push('componentWillMount'); } @@ -253,7 +253,7 @@ describe('ReactDOMServer', () => { return Component name: {this.state.name}; } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { lifecycle.push('componentWillUpdate'); } @@ -265,7 +265,7 @@ describe('ReactDOMServer', () => { lifecycle.push('shouldComponentUpdate'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { lifecycle.push('componentWillReceiveProps'); } @@ -297,7 +297,7 @@ describe('ReactDOMServer', () => { it('allows setState in componentWillMount without using DOM', () => { class Component extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({text: 'hello, world'}); } @@ -316,7 +316,7 @@ describe('ReactDOMServer', () => { this.state = {text: 'default state'}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({text: 'hello, world'}); } @@ -397,7 +397,7 @@ describe('ReactDOMServer', () => { } class Component extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({text: 'hello, world'}); } @@ -420,7 +420,7 @@ describe('ReactDOMServer', () => { it('warns with a no-op when an async setState is triggered', () => { class Foo extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({text: 'hello'}); setTimeout(() => { this.setState({text: 'error'}); @@ -446,7 +446,7 @@ describe('ReactDOMServer', () => { it('warns with a no-op when an async forceUpdate is triggered', () => { class Baz extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.forceUpdate(); setTimeout(() => { this.forceUpdate(); diff --git a/packages/react-dom/src/__tests__/ReactUpdates-test.js b/packages/react-dom/src/__tests__/ReactUpdates-test.js index 113fe74114685..ecf5c3467108a 100644 --- a/packages/react-dom/src/__tests__/ReactUpdates-test.js +++ b/packages/react-dom/src/__tests__/ReactUpdates-test.js @@ -399,7 +399,7 @@ describe('ReactUpdates', () => { let didUpdates = []; const UpdateLoggingMixin = { - unsafe_componentWillUpdate: function() { + UNSAFE_componentWillUpdate: function() { willUpdates.push(this.constructor.displayName); }, componentDidUpdate: function() { @@ -723,7 +723,7 @@ describe('ReactUpdates', () => { return
; } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { x.go(); } } @@ -746,7 +746,7 @@ describe('ReactUpdates', () => { class A extends React.Component { state = {x: 0}; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { a = this; } @@ -756,7 +756,7 @@ describe('ReactUpdates', () => { } class B extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { a.setState({x: 1}); } @@ -784,7 +784,7 @@ describe('ReactUpdates', () => { class A extends React.Component { state = {x: this.props.x}; - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { const newX = nextProps.x; this.setState({x: newX}, function() { // State should have updated by the time this callback gets called @@ -945,7 +945,7 @@ describe('ReactUpdates', () => { class Child extends React.Component { state = {updated: false}; - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { if (!once) { once = true; this.setState({updated: true}); @@ -1100,7 +1100,7 @@ describe('ReactUpdates', () => { let ops = []; class Foo extends React.Component { state = {a: false, b: false}; - unsafe_componentWillUpdate(_, nextState) { + UNSAFE_componentWillUpdate(_, nextState) { if (!nextState.a) { this.setState({a: true}); } @@ -1143,7 +1143,7 @@ describe('ReactUpdates', () => { let ops = []; class Foo extends React.Component { state = {a: false}; - unsafe_componentWillUpdate(_, nextState) { + UNSAFE_componentWillUpdate(_, nextState) { if (!nextState.a) { this.setState({a: true}); } @@ -1316,7 +1316,7 @@ describe('ReactUpdates', () => { componentDidMount() { this.setState({step: 1}); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { this.setState({step: 2}); } render() { diff --git a/packages/react-dom/src/__tests__/findDOMNode-test.js b/packages/react-dom/src/__tests__/findDOMNode-test.js index 33460adf9b176..a6f494e9b7ac0 100644 --- a/packages/react-dom/src/__tests__/findDOMNode-test.js +++ b/packages/react-dom/src/__tests__/findDOMNode-test.js @@ -88,7 +88,7 @@ describe('findDOMNode', () => { it('findDOMNode should not throw an error when called within a component that is not mounted', () => { class Bar extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { expect(ReactDOM.findDOMNode(this)).toBeNull(); } diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index 2e4bba43db6c8..7d3c5dc76102f 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -486,7 +486,7 @@ function resolve( if (initialState === undefined) { inst.state = initialState = null; } - if (inst.unsafe_componentWillMount || inst.componentWillMount) { + if (inst.UNSAFE_componentWillMount || inst.componentWillMount) { if (inst.componentWillMount) { if (__DEV__) { const componentName = getComponentName(Component) || 'Unknown'; @@ -495,7 +495,7 @@ function resolve( warning( false, '%s: componentWillMount() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillMount() instead.', + 'next major version. Please use UNSAFE_componentWillMount() instead.', componentName, ); didWarnAboutDeprecatedWillMount[componentName] = true; @@ -504,7 +504,7 @@ function resolve( inst.componentWillMount(); } else { - inst.unsafe_componentWillMount(); + inst.UNSAFE_componentWillMount(); } if (queue.length) { oldQueue = queue; diff --git a/packages/react-native-renderer/src/NativeMethodsMixin.js b/packages/react-native-renderer/src/NativeMethodsMixin.js index 54af829f37674..e2cad55458ac9 100644 --- a/packages/react-native-renderer/src/NativeMethodsMixin.js +++ b/packages/react-native-renderer/src/NativeMethodsMixin.js @@ -188,8 +188,8 @@ if (__DEV__) { invariant( !NativeMethodsMixin_DEV.componentWillMount && !NativeMethodsMixin_DEV.componentWillReceiveProps && - !NativeMethodsMixin_DEV.unsafe_componentWillMount && - !NativeMethodsMixin_DEV.unsafe_componentWillReceiveProps, + !NativeMethodsMixin_DEV.UNSAFE_componentWillMount && + !NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps, 'Do not override existing functions.', ); NativeMethodsMixin_DEV.componentWillMount = function() { @@ -198,10 +198,10 @@ if (__DEV__) { NativeMethodsMixin_DEV.componentWillReceiveProps = function(newProps) { throwOnStylesProp(this, newProps); }; - NativeMethodsMixin_DEV.unsafe_componentWillMount = function() { + NativeMethodsMixin_DEV.UNSAFE_componentWillMount = function() { throwOnStylesProp(this, this.props); }; - NativeMethodsMixin_DEV.unsafe_componentWillReceiveProps = function(newProps) { + NativeMethodsMixin_DEV.UNSAFE_componentWillReceiveProps = function(newProps) { throwOnStylesProp(this, newProps); }; } diff --git a/packages/react-reconciler/src/ReactFiberClassComponent.js b/packages/react-reconciler/src/ReactFiberClassComponent.js index 4815f39d4d472..9cdb92b8de3e6 100644 --- a/packages/react-reconciler/src/ReactFiberClassComponent.js +++ b/packages/react-reconciler/src/ReactFiberClassComponent.js @@ -380,6 +380,9 @@ export default function( const instance = new ctor(props, context); adoptClassInstance(workInProgress, instance); + // TODO (getDerivedStateFromProps) Call Component.getDerivedStateFromProps + // Merge the returned value into instance.state + // Cache unmasked context so we can avoid recreating masked context unless necessary. // ReactFiberContext usually updates this cache but can't for newly-created instances. if (needsContext) { @@ -398,13 +401,13 @@ export default function( warning( false, '%s: componentWillMount() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillMount() instead.', + 'next major version. Please use UNSAFE_componentWillMount() instead.', getComponentName(workInProgress), ); } instance.componentWillMount(); } else { - instance.unsafe_componentWillMount(); + instance.UNSAFE_componentWillMount(); } stopPhaseTimer(); @@ -435,7 +438,7 @@ export default function( warning( false, '%s: componentWillReceiveProps() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillReceiveProps() instead.', + 'next major version. Please use UNSAFE_componentWillReceiveProps() instead.', getComponentName(workInProgress), ); } @@ -445,15 +448,24 @@ export default function( stopPhaseTimer(); } else { startPhaseTimer(workInProgress, 'componentWillReceiveProps'); - instance.unsafe_componentWillReceiveProps(newProps, newContext); + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); stopPhaseTimer(); // Simulate an async bailout/interruption by invoking lifecycle twice. if (debugRenderPhaseSideEffects) { - instance.unsafe_componentWillReceiveProps(newProps, newContext); + instance.UNSAFE_componentWillReceiveProps(newProps, newContext); } } + // TODO (getDerivedStateFromProps) If both cWRP and static gDSFP methods exist, warn. + // Call cWRP first then static gDSFP; don't bother trying to sync apply setState() changes. + + // TODO (getDerivedStateFromProps) Call Component.getDerivedStateFromProps + + // TODO (getDerivedStateFromProps) Returned value should not be added to update queue. + // Just synchronously Object.assign it into instance.state + // This should be covered in a test too. + if (instance.state !== oldState) { if (__DEV__) { const componentName = getComponentName(workInProgress) || 'Component'; @@ -503,7 +515,7 @@ export default function( } if ( - typeof instance.unsafe_componentWillMount === 'function' || + typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function' ) { callComponentWillMount(workInProgress, instance); @@ -651,7 +663,7 @@ export default function( // during componentDidUpdate we pass the "current" props. if ( - (typeof instance.unsafe_componentWillReceiveProps === 'function' || + (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function') && (oldProps !== newProps || oldContext !== newContext) ) { @@ -713,7 +725,7 @@ export default function( if (shouldUpdate) { if ( - typeof instance.unsafe_componentWillUpdate === 'function' || + typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function' ) { if (typeof instance.componentWillUpdate === 'function') { @@ -721,7 +733,7 @@ export default function( warning( false, '%s: componentWillUpdate() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillUpdate() instead.', + 'next major version. Please use UNSAFE_componentWillUpdate() instead.', getComponentName(workInProgress), ); } @@ -731,12 +743,12 @@ export default function( stopPhaseTimer(); } else { startPhaseTimer(workInProgress, 'componentWillUpdate'); - instance.unsafe_componentWillUpdate(newProps, newState, newContext); + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); stopPhaseTimer(); // Simulate an async bailout/interruption by invoking lifecycle twice. if (debugRenderPhaseSideEffects) { - instance.unsafe_componentWillUpdate(newProps, newState, newContext); + instance.UNSAFE_componentWillUpdate(newProps, newState, newContext); } } } diff --git a/packages/react-reconciler/src/__tests__/ReactIncremental-test.js b/packages/react-reconciler/src/__tests__/ReactIncremental-test.js index 937f81f3341da..aadd7f51dc853 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncremental-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncremental-test.js @@ -571,16 +571,16 @@ describe('ReactIncremental', () => { ops.push('constructor: ' + props.prop); constructorCount++; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push('componentWillMount: ' + this.props.prop); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { ops.push('componentWillReceiveProps: ' + this.props.prop); } componentDidMount() { ops.push('componentDidMount: ' + this.props.prop); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { ops.push('componentWillUpdate: ' + this.props.prop); } componentDidUpdate() { @@ -1232,13 +1232,13 @@ describe('ReactIncremental', () => { class LifeCycle extends React.Component { state = {x: this.props.x}; - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { ops.push( 'componentWillReceiveProps:' + this.state.x + '-' + nextProps.x, ); this.setState({x: nextProps.x}); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push('componentWillMount:' + this.state.x + '-' + this.props.x); } componentDidMount() { @@ -1291,7 +1291,7 @@ describe('ReactIncremental', () => { super(props); this.state = {x: this.props.x + '(ctor)'}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push('componentWillMount:' + this.state.x); this.setState({x: this.props.x + '(willMount)'}); } @@ -1334,13 +1334,13 @@ describe('ReactIncremental', () => { let ops = []; class LifeCycle extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push('componentWillMount:' + this.props.x); } componentDidMount() { ops.push('componentDidMount:' + this.props.x); } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { ops.push( 'componentWillReceiveProps:' + this.props.x + '-' + nextProps.x, ); @@ -1349,7 +1349,7 @@ describe('ReactIncremental', () => { ops.push('shouldComponentUpdate:' + this.props.x + '-' + nextProps.x); return true; } - unsafe_componentWillUpdate(nextProps) { + UNSAFE_componentWillUpdate(nextProps) { ops.push('componentWillUpdate:' + this.props.x + '-' + nextProps.x); } componentDidUpdate(prevProps) { @@ -1429,21 +1429,21 @@ describe('ReactIncremental', () => { x: this.state.x + 1, }); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { instances.push(this); ops.push('componentWillMount:' + this.state.x); } componentDidMount() { ops.push('componentDidMount:' + this.state.x); } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { ops.push('componentWillReceiveProps'); } shouldComponentUpdate(nextProps, nextState) { ops.push('shouldComponentUpdate:' + this.state.x + '-' + nextState.x); return true; } - unsafe_componentWillUpdate(nextProps, nextState) { + UNSAFE_componentWillUpdate(nextProps, nextState) { ops.push('componentWillUpdate:' + this.state.x + '-' + nextState.x); } componentDidUpdate(prevProps, prevState) { @@ -1460,7 +1460,7 @@ describe('ReactIncremental', () => { // output unless it fully completed. class Wrap extends React.Component { state = {y: 0}; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { instances.push(this); } tick() { @@ -1570,13 +1570,13 @@ describe('ReactIncremental', () => { let ops = []; class LifeCycle extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { ops.push('componentWillMount'); } componentDidMount() { ops.push('componentDidMount'); } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { ops.push('componentWillReceiveProps'); } shouldComponentUpdate(nextProps) { @@ -1584,7 +1584,7 @@ describe('ReactIncremental', () => { // Bail return this.props.x !== nextProps.x; } - unsafe_componentWillUpdate(nextProps) { + UNSAFE_componentWillUpdate(nextProps) { ops.push('componentWillUpdate'); } componentDidUpdate(prevProps) { @@ -2282,7 +2282,7 @@ describe('ReactIncremental', () => { this.setState({setStateInCDU: false}); } } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { ops.push('componentWillReceiveProps'); this.setState({setStateInCDU: true}); } diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.internal.js index b3092981533ef..b6ad8bb1358a6 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.internal.js @@ -26,7 +26,7 @@ describe('ReactIncrementalErrorLogging', () => { spyOnProd(console, 'error'); class ErrorThrowingComponent extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { const error = new Error('componentWillMount error'); // Note: it's `true` on the Error prototype our test environment. // That lets us avoid asserting on warnings for each expected error. diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index 407d0b9052e10..1db7a44cf4423 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -237,10 +237,10 @@ describe('ReactDebugFiberPerf', () => { it('does not treat setState from cWM or cWRP as cascading', () => { class NotCascading extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({}); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { this.setState({}); } render() { @@ -276,10 +276,10 @@ describe('ReactDebugFiberPerf', () => { getChildContext() { return {foo: 42}; } - unsafe_componentWillMount() {} + UNSAFE_componentWillMount() {} componentDidMount() {} - unsafe_componentWillReceiveProps() {} - unsafe_componentWillUpdate() {} + UNSAFE_componentWillReceiveProps() {} + UNSAFE_componentWillUpdate() {} componentDidUpdate() {} componentWillUnmount() {} render() { diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js index cb9a8ae482410..c1414e077b19d 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.js @@ -31,7 +31,7 @@ describe('ReactIncrementalReflection', () => { // reaching into the updater. return this.updater.isMounted(this); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { instances.push(this); ops.push('componentWillMount', this._isMounted()); } @@ -75,7 +75,7 @@ describe('ReactIncrementalReflection', () => { _isMounted() { return this.updater.isMounted(this); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { instances.push(this); } componentWillUnmount() { @@ -128,14 +128,14 @@ describe('ReactIncrementalReflection', () => { let classInstance = null; class Component extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { classInstance = this; ops.push('componentWillMount', ReactNoop.findInstance(this)); } componentDidMount() { ops.push('componentDidMount', ReactNoop.findInstance(this)); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { ops.push('componentWillUpdate', ReactNoop.findInstance(this)); } componentDidUpdate() { diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js index ed3f172612c04..557475e7269e5 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.js @@ -331,7 +331,7 @@ describe('ReactIncrementalScheduling', () => { it('updates do not schedule a new callback if already inside a callback', () => { class Foo extends React.Component { state = {foo: 'foo'}; - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { ReactNoop.yield( 'has callback before setState: ' + ReactNoop.hasScheduledCallback(), ); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js index 5a2b6303c2dd6..c293a070bf18e 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js @@ -296,7 +296,7 @@ describe('ReactIncrementalUpdates', () => { class Foo extends React.Component { state = {}; - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { ops.push('componentWillReceiveProps'); this.setState({b: 'b'}); } diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 4b659aa049d8b..f71ca11e99e27 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -140,7 +140,7 @@ class ReactShallowRenderer { this._instance.updater = this._updater; if ( - typeof this._instance.unsafe_componentWillMount === 'function' || + typeof this._instance.UNSAFE_componentWillMount === 'function' || typeof this._instance.componentWillMount === 'function' ) { const beforeState = this._newState; @@ -152,7 +152,7 @@ class ReactShallowRenderer { warning( false, '%s: componentWillMount() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillMount() instead.', + 'next major version. Please use UNSAFE_componentWillMount() instead.', componentName, ); this._didWarnAboutLegacyWillMount[componentName] = true; @@ -160,7 +160,7 @@ class ReactShallowRenderer { } this._instance.componentWillMount(); } else { - this._instance.unsafe_componentWillMount(); + this._instance.UNSAFE_componentWillMount(); } // setState may have been called during cWM @@ -188,7 +188,7 @@ class ReactShallowRenderer { warning( false, '%s: componentWillReceiveProps() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillReceiveProps() instead.', + 'next major version. Please use UNSAFE_componentWillReceiveProps() instead.', componentName, ); this._didWarnAboutLegacyWillReceiveProps[componentName] = true; @@ -196,9 +196,9 @@ class ReactShallowRenderer { } this._instance.componentWillReceiveProps(props, context); } else if ( - typeof this._instance.unsafe_componentWillReceiveProps === 'function' + typeof this._instance.UNSAFE_componentWillReceiveProps === 'function' ) { - this._instance.unsafe_componentWillReceiveProps(props, context); + this._instance.UNSAFE_componentWillReceiveProps(props, context); } this._updateStateFromStaticLifecycle(props); @@ -230,7 +230,7 @@ class ReactShallowRenderer { warning( false, '%s: componentWillUpdate() is deprecated and will be removed in the ' + - 'next major version. Please use unsafe_componentWillUpdate() instead.', + 'next major version. Please use UNSAFE_componentWillUpdate() instead.', componentName, ); this._didWarnAboutLegacyWillUpdate[componentName] = true; @@ -239,9 +239,9 @@ class ReactShallowRenderer { this._instance.componentWillUpdate(props, state, context); } else if ( - typeof this._instance.unsafe_componentWillUpdate === 'function' + typeof this._instance.UNSAFE_componentWillUpdate === 'function' ) { - this._instance.unsafe_componentWillUpdate(props, state, context); + this._instance.UNSAFE_componentWillUpdate(props, state, context); } } @@ -263,7 +263,7 @@ class ReactShallowRenderer { if (__DEV__) { if ( typeof this._instance.componentWillReceiveProps === 'function' || - typeof this._instance.unsafe_componentWillReceiveProps === 'function' + typeof this._instance.UNSAFE_componentWillReceiveProps === 'function' ) { const componentName = getName(type, this._instance); if ( diff --git a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js index 7cf98e9a67e7c..efcb4afc4be59 100644 --- a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js @@ -27,11 +27,11 @@ describe('ReactShallowRenderer', () => { class SomeComponent extends React.Component { static getDerivedStateFromProps = logger('getDerivedStateFromProps'); - unsafe_componentWillMount = logger('componentWillMount'); + UNSAFE_componentWillMount = logger('componentWillMount'); componentDidMount = logger('componentDidMount'); - unsafe_componentWillReceiveProps = logger('componentWillReceiveProps'); + UNSAFE_componentWillReceiveProps = logger('componentWillReceiveProps'); shouldComponentUpdate = logger('shouldComponentUpdate'); - unsafe_componentWillUpdate = logger('componentWillUpdate'); + UNSAFE_componentWillUpdate = logger('componentWillUpdate'); componentDidUpdate = logger('componentDidUpdate'); componentWillUnmount = logger('componentWillUnmount'); render() { @@ -449,14 +449,14 @@ describe('ReactShallowRenderer', () => { getDerivedStateFromPropsParams.push(args); return null; } - unsafe_componentWillReceiveProps(...args) { + UNSAFE_componentWillReceiveProps(...args) { componentWillReceivePropsParams.push(...args); this.setState((...innerArgs) => { setStateParams.push(...innerArgs); return updatedState; }); } - unsafe_componentWillUpdate(...args) { + UNSAFE_componentWillUpdate(...args) { componentWillUpdateParams.push(...args); } shouldComponentUpdate(...args) { @@ -576,7 +576,7 @@ describe('ReactShallowRenderer', () => { it('can setState in componentWillMount when shallow rendering', () => { class SimpleComponent extends React.Component { - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({groovy: 'doovy'}); } @@ -596,7 +596,7 @@ describe('ReactShallowRenderer', () => { separator: '-', }; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({groovy: 'doovy'}); this.setState({doovy: 'groovy'}); } @@ -619,7 +619,7 @@ describe('ReactShallowRenderer', () => { separator: '-', }; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState(state => ({groovy: 'doovy'})); this.setState(state => ({doovy: state.groovy})); } @@ -640,7 +640,7 @@ describe('ReactShallowRenderer', () => { class SimpleComponent extends React.Component { state = {count: 0}; - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.updateState) { this.setState({count: 1}); } @@ -955,7 +955,7 @@ describe('ReactShallowRenderer', () => { }; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState( {hasUpdatedState: true}, () => (stateSuccessfullyUpdated = this.state.hasUpdatedState), @@ -984,7 +984,7 @@ describe('ReactShallowRenderer', () => { }; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({foo: 'bar'}, () => mockFn()); this.setState({foo: 'foobar'}, () => mockFn()); } @@ -1084,15 +1084,15 @@ describe('ReactShallowRenderer', () => { expect(() => shallowRenderer.render()).toWarnDev( 'Warning: ComponentWithWarnings: componentWillMount() is deprecated and will ' + 'be removed in the next major version. ' + - 'Please use unsafe_componentWillMount() instead.', + 'Please use UNSAFE_componentWillMount() instead.', ); expect(() => shallowRenderer.render()).toWarnDev([ 'Warning: ComponentWithWarnings: componentWillReceiveProps() is deprecated ' + 'and will be removed in the next major version. ' + - 'Please use unsafe_componentWillReceiveProps() instead.', + 'Please use UNSAFE_componentWillReceiveProps() instead.', 'Warning: ComponentWithWarnings: componentWillUpdate() is deprecated and will ' + 'be removed in the next major version. ' + - 'Please use unsafe_componentWillUpdate() instead.', + 'Please use UNSAFE_componentWillUpdate() instead.', ]); // Verify no duplicate warnings @@ -1105,7 +1105,7 @@ describe('ReactShallowRenderer', () => { static getDerivedStateFromProps(props, prevState) { return null; } - unsafe_componentWillReceiveProps(nextProps) {} + UNSAFE_componentWillReceiveProps(nextProps) {} render() { return null; } diff --git a/packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js b/packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js index 32145a8a655b2..224cb7670bcc2 100644 --- a/packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js +++ b/packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js @@ -38,16 +38,16 @@ describe('ReactAsyncClassComponent', () => { componentDidUpdate() { log.push('componentDidUpdate'); } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { log.push('componentWillMount'); } - unsafe_componentWillReceiveProps() { + UNSAFE_componentWillReceiveProps() { log.push('componentWillReceiveProps'); } componentWillUnmount() { log.push('componentWillUnmount'); } - unsafe_componentWillUpdate() { + UNSAFE_componentWillUpdate() { log.push('componentWillUpdate'); } shouldComponentUpdate() { diff --git a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee index ae6142b51c12b..a3bd6e8779e41 100644 --- a/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee +++ b/packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee @@ -136,7 +136,7 @@ describe 'ReactCoffeeScriptClass', -> constructor: (props) -> @state = bar: props.initialValue - unsafe_componentWillMount: -> + UNSAFE_componentWillMount: -> @setState bar: 'bar' render: -> @@ -232,20 +232,20 @@ describe 'ReactCoffeeScriptClass', -> constructor: -> @state = {} - unsafe_componentWillMount: -> + UNSAFE_componentWillMount: -> lifeCycles.push 'will-mount' componentDidMount: -> lifeCycles.push 'did-mount' - unsafe_componentWillReceiveProps: (nextProps) -> + UNSAFE_componentWillReceiveProps: (nextProps) -> lifeCycles.push 'receive-props', nextProps shouldComponentUpdate: (nextProps, nextState) -> lifeCycles.push 'should-update', nextProps, nextState true - unsafe_componentWillUpdate: (nextProps, nextState) -> + UNSAFE_componentWillUpdate: (nextProps, nextState) -> lifeCycles.push 'will-update', nextProps, nextState componentDidUpdate: (prevProps, prevState) -> diff --git a/packages/react/src/__tests__/ReactContextValidator-test.js b/packages/react/src/__tests__/ReactContextValidator-test.js index cd88d6f45f8bc..f762b6b21b6b3 100644 --- a/packages/react/src/__tests__/ReactContextValidator-test.js +++ b/packages/react/src/__tests__/ReactContextValidator-test.js @@ -89,7 +89,7 @@ describe('ReactContextValidator', () => { }; class Component extends React.Component { - unsafe_componentWillReceiveProps(nextProps, nextContext) { + UNSAFE_componentWillReceiveProps(nextProps, nextContext) { actualComponentWillReceiveProps = nextContext; return true; } @@ -99,7 +99,7 @@ describe('ReactContextValidator', () => { return true; } - unsafe_componentWillUpdate(nextProps, nextState, nextContext) { + UNSAFE_componentWillUpdate(nextProps, nextState, nextContext) { actualComponentWillUpdate = nextContext; } diff --git a/packages/react/src/__tests__/ReactES6Class-test.js b/packages/react/src/__tests__/ReactES6Class-test.js index 93cd9e55cf606..b7ef26504a4ff 100644 --- a/packages/react/src/__tests__/ReactES6Class-test.js +++ b/packages/react/src/__tests__/ReactES6Class-test.js @@ -147,7 +147,7 @@ describe('ReactES6Class', () => { super(props); this.state = {bar: props.initialValue}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({bar: 'bar'}); } render() { @@ -257,20 +257,20 @@ describe('ReactES6Class', () => { super(); this.state = {}; } - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { lifeCycles.push('will-mount'); } componentDidMount() { lifeCycles.push('did-mount'); } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { lifeCycles.push('receive-props', nextProps); } shouldComponentUpdate(nextProps, nextState) { lifeCycles.push('should-update', nextProps, nextState); return true; } - unsafe_componentWillUpdate(nextProps, nextState) { + UNSAFE_componentWillUpdate(nextProps, nextState) { lifeCycles.push('will-update', nextProps, nextState); } componentDidUpdate(prevProps, prevState) { diff --git a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts index aa4e1a5e26d96..3dce5bcd4bde6 100644 --- a/packages/react/src/__tests__/ReactTypeScriptClass-test.ts +++ b/packages/react/src/__tests__/ReactTypeScriptClass-test.ts @@ -117,7 +117,7 @@ class RenderOnce extends React.Component { state = { bar: this.props.initialValue, }; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { this.setState({bar: 'bar'}); } render() { @@ -206,20 +206,20 @@ let lifeCycles = []; class NormalLifeCycles extends React.Component { props: any; state = {}; - unsafe_componentWillMount() { + UNSAFE_componentWillMount() { lifeCycles.push('will-mount'); } componentDidMount() { lifeCycles.push('did-mount'); } - unsafe_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps) { lifeCycles.push('receive-props', nextProps); } shouldComponentUpdate(nextProps, nextState) { lifeCycles.push('should-update', nextProps, nextState); return true; } - unsafe_componentWillUpdate(nextProps, nextState) { + UNSAFE_componentWillUpdate(nextProps, nextState) { lifeCycles.push('will-update', nextProps, nextState); } componentDidUpdate(prevProps, prevState) { diff --git a/packages/react/src/__tests__/createReactClassIntegration-test.js b/packages/react/src/__tests__/createReactClassIntegration-test.js index bb85f45d366f8..851642881f1a2 100644 --- a/packages/react/src/__tests__/createReactClassIntegration-test.js +++ b/packages/react/src/__tests__/createReactClassIntegration-test.js @@ -402,7 +402,7 @@ describe('create-react-class-integration', () => { const container = document.createElement('div'); // Note: The below lifecycle warnings are unavoidable for now, - // Until create-react-class recognizes the unsafe_* methods. + // Until create-react-class recognizes the UNSAFE_* methods. // (If we try to use them before them, it will error because // we are defining the same method twice.) expect(() => ReactDOM.render(, container)).toWarnDev([ @@ -411,13 +411,13 @@ describe('create-react-class-integration', () => { 'to prevent memory leaks.', 'Warning: MyComponent: componentWillMount() is deprecated and will be ' + 'removed in the next major version. Please use ' + - 'unsafe_componentWillMount() instead.', + 'UNSAFE_componentWillMount() instead.', ]); expect(() => ReactDOM.render(, container)).toWarnDev( 'Warning: MyComponent: componentWillUpdate() is deprecated and will be ' + 'removed in the next major version. Please use ' + - 'unsafe_componentWillUpdate() instead.', + 'UNSAFE_componentWillUpdate() instead.', ); ReactDOM.unmountComponentAtNode(container);