Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React: Remove the usage of the componentWillMount lifecycle #7282

Merged
merged 3 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/higher-order/with-focus-return/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ function withFocusReturn( WrappedComponent ) {

this.setIsFocusedTrue = () => this.isFocused = true;
this.setIsFocusedFalse = () => this.isFocused = false;
}

componentWillMount() {
this.activeElementOnMount = document.activeElement;
}

Expand Down
3 changes: 2 additions & 1 deletion components/slot-fill/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { Component, createPortal } from '@wordpress/element';
let occurrences = 0;

class Fill extends Component {
componentWillMount() {
constructor() {
super( ...arguments );
this.occurrence = ++occurrences;
}

Expand Down
2 changes: 1 addition & 1 deletion core-blocks/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function getEmbedBlockSettings( { title, description, icon, category = 'embed',
};
}

componentWillMount() {
componentDidMount() {
this.doServerSideRender();
}

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Gutenberg's deprecation policy is intended to support backwards-compatibility for two minor releases, when possible. The current deprecations are listed below and are grouped by _the version at which they will be removed completely_. If your plugin depends on these behaviors, you must update to the recommended alternative before the noted version.

## 3.3.0

- `useOnce: true` has been removed from the Block API. Please use `supports.multiple: false` instead.
- Serializing components using `componentWillMount` lifecycle method. Please use the constructor instead.

## 3.2.0

Expand Down
1 change: 1 addition & 0 deletions packages/element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"main": "build/index.js",
"module": "build-module/index.js",
"dependencies": {
"@wordpress/deprecated": "^1.0.0-alpha.1",
"@wordpress/is-shallow-equal": "1.0.2",
"lodash": "4.17.5",
"react": "16.3.2",
Expand Down
10 changes: 10 additions & 0 deletions packages/element/src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
import { isEmpty, castArray, omit, kebabCase } from 'lodash';

/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -443,6 +448,11 @@ export function renderComponent( Component, props, context = {} ) {

if ( typeof instance.componentWillMount === 'function' ) {
instance.componentWillMount();
deprecated( 'componentWillMount', {
version: '3.3',
alternative: 'the constructor',
plugin: 'Gutenberg',
} );
}

if ( typeof instance.getChildContext === 'function' ) {
Expand Down
1 change: 1 addition & 0 deletions packages/element/src/test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ describe( 'renderComponent()', () => {

const result = renderComponent( Example, {} );

expect( console ).toHaveWarned();
expect( result ).toBe( 'constructedwillMounted' );
} );

Expand Down