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

changing name of deprecated react lifecycle methods #2059

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

Conversation

ranneyd
Copy link

@ranneyd ranneyd commented Oct 30, 2020

#1748

  • Instead of switching to getDerivedStateFromProps, I figured using the UNSAFE versions of the functions was less disruptive. Perhaps the lib will move to a functional/hooks-based implementation some day.
  • The UNSAFE prefix on the function names upset eslint's camelcase rule. I copied the config from here but added the allow property

@ranneyd ranneyd mentioned this pull request Oct 30, 2020
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

You'll also want to update .travis.yml so it stops testing on React 14 and 15, and start testing on React 17.

The latter means this is blocked on enzymejs/enzyme#2430 - so another alternative is requiring ^16.3 and waiting until a future PR to add (in a semver-minor) v17 support.

package.json Outdated
Comment on lines 103 to 104
"react": "^16.3.0 || ^17.0.0",
"react-dom": "^16.3.0 || ^17.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

just calling out that this makes it a breaking change.

@@ -109,7 +109,7 @@ class CalendarMonth extends React.PureComponent {
this.setMonthTitleHeightTimeout = setTimeout(this.setMonthTitleHeight, 0);
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
Copy link
Member

Choose a reason for hiding this comment

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

if we're doing the breaking change, we might as well migrate to getDerivedStateFromProps where we can? It's ok to keep the unsafe versions where that's not easy tho.

Copy link
Author

Choose a reason for hiding this comment

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

I have a few thoughts on this:

  • I want to rock the boat with this PR as little as possible. If people are upgrading from an older react to 16.3+, then upgrading this, if they have a bug it would be nice to say fairly confidently that it wasn't this and probably part of some other part of their migration.
  • Related, a ton of the logic in these components is in these lifecycle methods, so I see any substantive change to them as a larger-scope change.
  • From my understanding, these methods aren't going anywhere anytime soon. My understanding is the react team has great interest in discouraging their use rather than removing them.
  • If you think this is the time/PR to do this lmk and I can see what I can do. Might be more appropriate to do it in two parts.
  • Depending on what the future holds, this lib might go the way of many of the other libs out there and get a functional, hooks-based refactor. Maybe instead of migrating all this huge lifecycle method logic twice we just wait until that day comes (though I believe the migration to getDerivedStateFromProps is not nearly on the same scale as a migration to hooks, which would be...non-trivial.)

I will say in general I'm all about the "while we're at it" mentality. If it were my own repo or wasn't 427,576 weekly downloads then I'd feel more comfortable just doing it 😂 .

My vote is to do it this dumb, rename-only way first to get the warnings out and get the compatibility there, then either have a follow-up PR or include this in future refactoring conversations/planning.

Copy link
Member

Choose a reason for hiding this comment

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

If we're going to migrate to hooks any time soon, we'd need to require React v16.9 now, and not just v16.3, even if we do this PR as-is first, and change other things later.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah definitely not advocating hooks migration in the near-term.

@ljharb ljharb added the semver-major: breaking change A non-backwards-compatible change; anything that breaks code - including adding a peerDep. label Oct 31, 2020
@ranneyd
Copy link
Author

ranneyd commented Nov 2, 2020

@ljharb just removed < 16 from .travis.yml. I also removed react 17 from the dependencies; we can add that in later when enzyme et al. are updated.

@ranneyd ranneyd force-pushed the unsafe-componentwillreceiveprops branch from 2631bac to e171106 Compare November 2, 2020 16:36
@andrew-pyle
Copy link

Is this still blocked? Any way a contributor could help? react-dates is preventing migration to React 17 for me.

@ljharb
Copy link
Member

ljharb commented Feb 24, 2021

Yes; this still needs rebasing, but also would still be a breaking change.

@alex-pex

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major: breaking change A non-backwards-compatible change; anything that breaks code - including adding a peerDep.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants