Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e709e30
Added unsafe_* lifecycles and deprecation warnings
bvaughn Jan 16, 2018
404944e
Ran lifecycle hook codemod over project
bvaughn Jan 16, 2018
bd300b3
Manually migrated CoffeeScript and TypeScript tests
bvaughn Jan 16, 2018
2868176
Added inline note to createReactClassIntegration-test
bvaughn Jan 16, 2018
8679926
Udated NativeMethodsMixin with new lifecycle hooks
bvaughn Jan 16, 2018
64f27d7
Added static getDerivedStateFromProps to ReactPartialRenderer
bvaughn Jan 17, 2018
1047182
Added getDerivedStateFromProps to shallow renderer
bvaughn Jan 17, 2018
035c220
Dedupe and DEV-only deprecation warning in server renderer
bvaughn Jan 17, 2018
8d0e001
Renamed unsafe_* prefix to UNSAFE_* to be more noticeable
bvaughn Jan 17, 2018
b71ca93
Added getDerivedStateFromProps to ReactFiberClassComponent
bvaughn Jan 17, 2018
09c39d0
Warn about UNSAFE_componentWillRecieveProps misspelling
bvaughn Jan 17, 2018
286df77
Added tests to createReactClassIntegration for new lifecycles
bvaughn Jan 17, 2018
b699543
Added warning for stateless functional components with gDSFP
bvaughn Jan 17, 2018
68f2fe7
Added createReactClass test for static gDSFP
bvaughn Jan 18, 2018
2d9f75d
Moved lifecycle deprecation warnings behind (disabled) feature flag
bvaughn Jan 18, 2018
8f125b7
Tidying up
bvaughn Jan 18, 2018
1d3e3d5
Merge branch 'master' into rfc-6
bvaughn Jan 18, 2018
d95ec49
Tweaked warning message wording slightly
bvaughn Jan 18, 2018
b940938
Replaced truthy partialState checks with != null
bvaughn Jan 18, 2018
6cd0a8e
Call getDerivedStateFromProps via .call(null) to prevent type access
bvaughn Jan 18, 2018
7572667
Move shallow-renderer didWarn* maps off the instance
bvaughn Jan 18, 2018
361a2cf
Only call getDerivedStateFromProps if props instance has changed
bvaughn Jan 18, 2018
8178d52
Avoid creating new state object if not necessary
bvaughn Jan 18, 2018
8d67e27
Inject state as a param to callGetDerivedStateFromProps
bvaughn Jan 18, 2018
53770c3
Explicitly warn about uninitialized state before calling getDerivedSt…
bvaughn Jan 18, 2018
3772ee2
Improved wording for deprecation lifecycle warnings
bvaughn Jan 18, 2018
4dfa6e1
Merge branch 'master' into rfc-6
bvaughn Jan 18, 2018
5609031
Fix state-regression for module-pattern components
bvaughn Jan 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Warn about UNSAFE_componentWillRecieveProps misspelling
  • Loading branch information
bvaughn committed Jan 17, 2018
commit 09c39d079c51e12bea5d9aef5747e1a19d0e8191
8 changes: 8 additions & 0 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ export default function(
'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
name,
);
const noUnsafeComponentWillRecieveProps =
typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
warning(
noUnsafeComponentWillRecieveProps,
'%s has a method called ' +
'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?',
name,
);
const hasMutatedProps = instance.props !== workInProgress.pendingProps;
warning(
instance.props === undefined || !hasMutatedProps,
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,23 @@ describe 'ReactCoffeeScriptClass', ->
)
undefined

it 'should warn when misspelling UNSAFE_componentWillReceiveProps', ->
class NamedComponent extends React.Component
UNSAFE_componentWillRecieveProps: ->
false

render: ->
span
className: 'foo'

expect(->
test React.createElement(NamedComponent), 'SPAN', 'foo'
).toWarnDev(
'Warning: NamedComponent has a method called UNSAFE_componentWillRecieveProps().
Did you mean UNSAFE_componentWillReceiveProps()?'
)
undefined

it 'should throw AND warn when trying to access classic APIs', ->
instance =
test Inner(name: 'foo'), 'DIV', 'foo'
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/__tests__/ReactES6Class-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,23 @@ describe('ReactES6Class', () => {
);
});

it('should warn when misspelling UNSAFE_componentWillReceiveProps', () => {
class NamedComponent extends React.Component {
UNSAFE_componentWillRecieveProps() {
return false;
}
render() {
return <span className="foo" />;
}
}

expect(() => test(<NamedComponent />, 'SPAN', 'foo')).toWarnDev(
'Warning: ' +
'NamedComponent has a method called UNSAFE_componentWillRecieveProps(). ' +
'Did you mean UNSAFE_componentWillReceiveProps()?',
);
});

it('should throw AND warn when trying to access classic APIs', () => {
const instance = test(<Inner name="foo" />, 'DIV', 'foo');
expect(() =>
Expand Down
20 changes: 20 additions & 0 deletions packages/react/src/__tests__/ReactTypeScriptClass-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ class MisspelledComponent2 extends React.Component {
}
}

// it should warn when misspelling UNSAFE_componentWillReceiveProps
class MisspelledComponent3 extends React.Component {
UNSAFE_componentWillRecieveProps() {
return false;
}
render() {
return React.createElement('span', {className: 'foo'});
}
}

// it supports this.context passed via getChildContext
class ReadContext extends React.Component {
static contextTypes = {bar: PropTypes.string};
Expand Down Expand Up @@ -537,6 +547,16 @@ describe('ReactTypeScriptClass', function() {
);
});

it('should warn when misspelling UNSAFE_componentWillReceiveProps', function() {
expect(() =>
test(React.createElement(MisspelledComponent3), 'SPAN', 'foo')
).toWarnDev(
'Warning: ' +
'MisspelledComponent3 has a method called UNSAFE_componentWillRecieveProps(). ' +
'Did you mean UNSAFE_componentWillReceiveProps()?'
);
});

it('should throw AND warn when trying to access classic APIs', function() {
const instance = test(
React.createElement(Inner, {name: 'foo'}),
Expand Down