Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Replace use of deprecated lifecycle method componentWillReceiveProps #255

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rynobax
Copy link

@rynobax rynobax commented Oct 7, 2018

Summary & motivation

When rendered in React Strict mode, this library generates warnings because it is using the deprecated lifecycle method componentWillReceiveProps. I moved the code inside of componentWillReceiveProps into componentDidUpdate, as suggested in this React blog post.

Testing & documentation

The changes to the the code needed to remove cWRP was pretty straightforward. However, Enzyme v2 does not call cDU, so I migrated the tests to enzyme v3 in order to get them to pass. There are other ways to keep the tests passing without upgrading Enzyme (namely switching from shallow rendering to full mounting), but this seemed the simplest.

I also fixed a bug in the demo page that was exposed by strict mode, where a request was being fired in the constructor, and the handler was running before the component had been mounted (which threw an error). Moving the request into componentDidMount fixed it.

@asolove-stripe
Copy link
Contributor

@rynobax thanks for this PR! On a cursory look, it seems like a change worth making. Can you look into the CI error and get things green so we can do a full review? Thanks!

@rynobax
Copy link
Author

rynobax commented Oct 9, 2018

CI is passing now

Copy link
Contributor

@asolove-stripe asolove-stripe left a comment

Choose a reason for hiding this comment

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

@rynobax thanks for the PR! These changes look good to me.

That said, I think they'll need to wait for a new major version to merge.

While the movement of logic between lifecycle methods is probably safe for most apps, it's possible that someone with a particularly complex usage could be relying on the exact order in which these things happen. (That an element's DOM is already mutated before render on the parent component is called, for example.)

@rynobax
Copy link
Author

rynobax commented Oct 12, 2018

👍

@caseybaggz
Copy link

@rynobax you planning on fixing the simple conflict so this can get merged?

@rynobax
Copy link
Author

rynobax commented Jan 31, 2019

Rebased the branch and let yarn fix the conflict

@atty-stripe
Copy link
Contributor

atty-stripe commented Jan 31, 2019

Thank you for updating this PR! Unfortunately we are no closer to a major version release than when this PR was opened. We will keep this in mind for the future when other breaking changes are introduced.

(Happy to take a separate PR for the enzyme changes though if you'd like)

@y0hnn
Copy link

y0hnn commented Aug 17, 2019

Hi, now Rect 16.9 deprecates componentWillReceiveProps, it would be useful to merge this!

@asolove-stripe
Copy link
Contributor

@yohannprigent: good point! Looks like I need to rebase and review this, since it's a bit old, but we should get 16.9 support working soon.

@asolove-stripe
Copy link
Contributor

A fix for this is now in master and we will cut a 5.0 release shortly, so going to close. Thanks for the PR and sorry we took so long to get around to this!

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants