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

chore(AutoControlledComponent): Remove unsafe lifecycles #3245

Conversation

kohakukun
Copy link
Contributor

Remove unsafe lifecycles from AutoControlledComponent and affected
components:

  • componentWillMount
  • componentWillRecieveProps
  • componentWillUpdate

Relates to #2732

Remove unsafe lifecycles from `AutoControlledComponent` and affected
components:
- `componentWillMount`
- `componentWillRecieveProps`
- `componentWillUpdate`

Relates to Semantic-Org#2732
@codecov-io
Copy link

Codecov Report

Merging #3245 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3245      +/-   ##
==========================================
+ Coverage   99.92%   99.96%   +0.03%     
==========================================
  Files         169      169              
  Lines        2802     2802              
==========================================
+ Hits         2800     2801       +1     
+ Misses          2        1       -1
Impacted Files Coverage Δ
src/modules/Dropdown/Dropdown.js 100% <100%> (+0.23%) ⬆️
src/modules/Checkbox/Checkbox.js 100% <100%> (ø) ⬆️
src/modules/Accordion/AccordionAccordion.js 100% <100%> (ø) ⬆️
src/modules/Search/Search.js 99.46% <100%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e83af2...babd63d. Read the comment docs.

@kohakukun
Copy link
Contributor Author

kohakukun commented Oct 28, 2018

Many changes where introduced by the formater in defined in the hooks. Sorry for the extra work.

This PR cannot be breaked further as inherited components are affected

'State will not be set.',
'Only props in static autoControlledProps will be set on state.',
].join(' '),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot simply rename componentWillReceiveProps() to componentDidUpdate() there because we will have an additional render() after setState(), just compare

componentWillReceiveProps() 
render() 
// vs
render() 
componentDidUpdate 
render() 
componentDidUpdate 

Example: https://codesandbox.io/s/4x35y87rl4


The right way is to use there getDerivedStateFromProps(). This will be more complicated refactor :(

Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a comment about the changes, we need to make more work there.

Thank you for the start 👍


However, we can safely make changes in MountNode for example: https://github.com/Semantic-Org/Semantic-UI-React/blob/v0.83.0/src/addons/MountNode/MountNode.js#L38

@kohakukun
Copy link
Contributor Author

Sure, I'll try to work on define the same logic with getDerivedStateFromProps.

However, we can safely make changes in MountNode for example: https://github.com/Semantic-Org/Semantic-UI-React/blob/v0.83.0/src/addons/MountNode/MountNode.js#L38
What do you mean by that?

@layershifter
Copy link
Member

What do you mean by that?

We can update MountNode component and replace there componentWillMount with componentDidMount.

@layershifter
Copy link
Member

Hey @kohakukun

I recently merged #3303, it has a very cool simplification of componentWillReceiveProps(). We can migrate to getDerivedStateFromProps() without any problems. Are you still interested in this PR?

@kohakukun
Copy link
Contributor Author

Sorry for the slow reply

@kohakukun kohakukun closed this Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants