-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
RFC 6: Deprecate unsafe lifecycles #12028
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e709e30
Added unsafe_* lifecycles and deprecation warnings
bvaughn 404944e
Ran lifecycle hook codemod over project
bvaughn bd300b3
Manually migrated CoffeeScript and TypeScript tests
bvaughn 2868176
Added inline note to createReactClassIntegration-test
bvaughn 8679926
Udated NativeMethodsMixin with new lifecycle hooks
bvaughn 64f27d7
Added static getDerivedStateFromProps to ReactPartialRenderer
bvaughn 1047182
Added getDerivedStateFromProps to shallow renderer
bvaughn 035c220
Dedupe and DEV-only deprecation warning in server renderer
bvaughn 8d0e001
Renamed unsafe_* prefix to UNSAFE_* to be more noticeable
bvaughn b71ca93
Added getDerivedStateFromProps to ReactFiberClassComponent
bvaughn 09c39d0
Warn about UNSAFE_componentWillRecieveProps misspelling
bvaughn 286df77
Added tests to createReactClassIntegration for new lifecycles
bvaughn b699543
Added warning for stateless functional components with gDSFP
bvaughn 68f2fe7
Added createReactClass test for static gDSFP
bvaughn 2d9f75d
Moved lifecycle deprecation warnings behind (disabled) feature flag
bvaughn 8f125b7
Tidying up
bvaughn 1d3e3d5
Merge branch 'master' into rfc-6
bvaughn d95ec49
Tweaked warning message wording slightly
bvaughn b940938
Replaced truthy partialState checks with != null
bvaughn 6cd0a8e
Call getDerivedStateFromProps via .call(null) to prevent type access
bvaughn 7572667
Move shallow-renderer didWarn* maps off the instance
bvaughn 361a2cf
Only call getDerivedStateFromProps if props instance has changed
bvaughn 8178d52
Avoid creating new state object if not necessary
bvaughn 8d67e27
Inject state as a param to callGetDerivedStateFromProps
bvaughn 53770c3
Explicitly warn about uninitialized state before calling getDerivedSt…
bvaughn 3772ee2
Improved wording for deprecation lifecycle warnings
bvaughn 4dfa6e1
Merge branch 'master' into rfc-6
bvaughn 5609031
Fix state-regression for module-pattern components
bvaughn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.internal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDOM; | ||
let ReactFeatureFlags; | ||
|
||
describe('ReactComponentLifeCycle', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
|
||
ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
ReactFeatureFlags.warnAboutDeprecatedLifecycles = true; | ||
|
||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
}); | ||
|
||
// TODO (RFC #6) Merge this back into ReactComponentLifeCycles-test once | ||
// the 'warnAboutDeprecatedLifecycles' feature flag has been removed. | ||
it('warns about deprecated unsafe lifecycles', function() { | ||
class MyComponent extends React.Component { | ||
componentWillMount() {} | ||
componentWillReceiveProps() {} | ||
componentWillUpdate() {} | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
const container = document.createElement('div'); | ||
expect(() => ReactDOM.render(<MyComponent x={1} />, container)).toWarnDev([ | ||
'Warning: MyComponent: componentWillMount() is deprecated and will be ' + | ||
'removed in the next major version.', | ||
]); | ||
|
||
expect(() => ReactDOM.render(<MyComponent x={2} />, container)).toWarnDev([ | ||
'Warning: MyComponent: componentWillReceiveProps() is deprecated and ' + | ||
'will be removed in the next major version.', | ||
'Warning: MyComponent: componentWillUpdate() is deprecated and will be ' + | ||
'removed in the next major version.', | ||
]); | ||
|
||
// Dedupe check (instantiate and update) | ||
ReactDOM.render(<MyComponent key="new" x={1} />, container); | ||
ReactDOM.render(<MyComponent key="new" x={2} />, container); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this?
(link) can point to some fburl that we write later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now the link can be your RFC :)