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

[v4] StrictMode warns even when no unsafe methods are used #860

Closed
apostolos opened this issue Feb 14, 2018 · 4 comments
Closed

[v4] StrictMode warns even when no unsafe methods are used #860

apostolos opened this issue Feb 14, 2018 · 4 comments

Comments

@apostolos
Copy link

Environment

React Hot Loader version: 4.0.0-beta.22
React: 16.3+

Description

When enabling Strict/Async mode for any part of the tree that contains React components, React warns about unsafe lifecycle methods even when the components don't use them.

This only happens when react-hot-loader/babel plugin is loaded.

Expected behavior

There should be no warnings.

Actual behavior

Warning: Unsafe lifecycle methods were found within a strict-mode tree:

componentWillReceiveProps: Please update the following components to use static getDerivedStateFromProps instead: Test

componentWillUpdate: Please update the following components to use componentDidUpdate instead: Test

Learn more about this warning here:
https://fb.me/react-strict-mode-warnings

Reproducible Demo

import * as React from 'react';
import { render } from 'react-dom';

class Test extends React.Component {
  render() {
    return <div>test strict</div>;
  }
}

render(
  <React.StrictMode>
    <Test />
  </React.StrictMode>,
  document.getElementById('app')
);
@theKashey
Copy link
Collaborator

  • componentWillUpdate is already removed
  • componentWillMount to be replaced by componentDidMount
  • we could not replace componentWillReceiveProps yet, but as long it will coexist with React until version 17 - we might just prefix it by "UNSAFE" for a while.

gregberge pushed a commit that referenced this issue Feb 16, 2018
* safe define displayName, fix #845

* stand children did not exists, fix #843

* improve TS documentation

* add SSR+HRM example

* subrender - fix deferred updates

* dont fix package version

* should have react as a peer dep

* use didMount instead of will, related to #860
@JustFly1984
Copy link

Sorry to bug you out, but I have issues with <StictMode /> in gatsby v2. it has [email protected] in dependencies, and I'm using it for example in my attempt to make new google maps api for React. I need to test it with SSR, and at the same time to test it in strict mode. It seems like I can't do both at the same time.

@JustFly1984
Copy link

Should I make new issue? I've made an issue in gatsby: gatsbyjs/gatsby#10179

@theKashey
Copy link
Collaborator

@JustFly1984 - just provide a demo to double check.
My tests are all green - RHL does not amending any component with componentWillMount anymore

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

No branches or pull requests

4 participants