Skip to content

Commit

Permalink
[PR] Add componentDidCatch React lifecycle
Browse files Browse the repository at this point in the history
Summary:
Closes #5139

Adds type that [matches callsite for `componentDidCatch`](https://github.com/facebook/react/blob/b52a5624e95f77166ffa520476d68231640692f9/packages/react-reconciler/src/ReactFiberScheduler.js#L1309)

The Flow type for `info` is defined here as well: https://github.com/facebook/react/blob/b52a5624e95f77166ffa520476d68231640692f9/packages/react-reconciler/src/ReactFiberScheduler.js#L29-L31
Closes #6044

Reviewed By: gabelevi

Differential Revision: D8550380

Pulled By: mrkev

fbshipit-source-id: eaae81ae0f36c747abd295c924ac1e13191e5fbf
  • Loading branch information
eliperkins authored and facebook-github-bot committed Jun 26, 2018
1 parent ad642c1 commit eb51ae5
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 257 deletions.
6 changes: 6 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ declare class React$Component<Props, State = void> {
prevContext: any,
): mixed;
componentWillUnmount(): mixed;
componentDidCatch(
error: Error,
info: {
componentStack: string,
}
): mixed;

// long tail of other stuff not modeled very well

Expand Down
8 changes: 4 additions & 4 deletions tests/getters_and_setters/getters_and_setters.exp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ References:
react.js:17:13
17| (<Example a="bad" />); // error: number ~> string
^^^^^ [1]
<BUILTINS>/react.js:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:319:36
319| number: React$PropType$Primitive<number>;
^^^^^^ [2]


Expand All @@ -506,8 +506,8 @@ References:
react.js:18:20
18| (<Example a={0} c={0} />); // error: number ~> string
^ [1]
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down
36 changes: 18 additions & 18 deletions tests/more_react/more_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ Cannot call `checkPropTypes` because function [1] requires another argument.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:199:41
<BUILTINS>/react.js:205:41
v---
199| declare export function checkPropTypes<V>(
200| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
201| values: V,
202| location: string,
203| componentName: string,
204| getStack: ?(() => ?string)
205| ) : void;
205| declare export function checkPropTypes<V>(
206| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
207| values: V,
208| location: string,
209| componentName: string,
210| getStack: ?(() => ?string)
211| ) : void;
-------^ [1]


Expand All @@ -79,15 +79,15 @@ Cannot call `checkPropTypes` because function [1] requires another argument.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:199:41
<BUILTINS>/react.js:205:41
v---
199| declare export function checkPropTypes<V>(
200| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
201| values: V,
202| location: string,
203| componentName: string,
204| getStack: ?(() => ?string)
205| ) : void;
205| declare export function checkPropTypes<V>(
206| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
207| values: V,
208| location: string,
209| componentName: string,
210| getStack: ?(() => ?string)
211| ) : void;
-------^ [1]


Expand All @@ -113,8 +113,8 @@ References:
checkPropTypes.js:12:91
12| checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent', () => 123); // error: number ~> string
^^^ [1]
<BUILTINS>/react.js:204:24
204| getStack: ?(() => ?string)
<BUILTINS>/react.js:210:24
210| getStack: ?(() => ?string)
^^^^^^ [2]


Expand Down
66 changes: 33 additions & 33 deletions tests/new_react/new_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ References:
classes.js:39:15
39| var foo: $jsx<number> = <Foo/>;
^^^^^^ [1]
<BUILTINS>/react.js:159:5
159| | string
<BUILTINS>/react.js:165:5
165| | string
^^^^^^ [2]


Expand All @@ -189,8 +189,8 @@ Cannot assign `this.props.x` to `_` because number [1] is incompatible with stri
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:319:36
319| number: React$PropType$Primitive<number>;
^^^^^^ [1]
classes.js:57:12
57| var _: string = this.props.x;
Expand Down Expand Up @@ -316,8 +316,8 @@ References:
classes.js:79:22
79| var foo_legacy: $jsx<number> = <FooLegacy/>;
^^^^^^ [1]
<BUILTINS>/react.js:159:5
159| | string
<BUILTINS>/react.js:165:5
165| | string
^^^^^^ [2]


Expand Down Expand Up @@ -388,8 +388,8 @@ Cannot assign `this.props.z` to `qux` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:319:36
319| number: React$PropType$Primitive<number>;
^^^^^^ [1]
new_react.js:19:18
19| var qux: string = this.props.z;
Expand All @@ -405,8 +405,8 @@ Cannot assign `this.props.x` to `w` because string [1] is incompatible with numb
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [1]
new_react.js:20:15
20| var w:number = this.props.x;
Expand Down Expand Up @@ -439,8 +439,8 @@ References:
new_react.js:29:23
29| var element = <C x = {0}/>;
^ [1]
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down Expand Up @@ -475,14 +475,14 @@ Cannot assign `C.displayName` to `x` because:
^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:83:24
83| static displayName?: ?string;
<BUILTINS>/react.js:89:24
89| static displayName?: ?string;
^^^^^^^ [1]
new_react.js:32:8
32| var x: number = C.displayName;
^^^^^^ [2]
<BUILTINS>/react.js:83:25
83| static displayName?: ?string;
<BUILTINS>/react.js:89:25
89| static displayName?: ?string;
^^^^^^ [3]


Expand Down Expand Up @@ -545,8 +545,8 @@ Cannot assign `this.props.x` to `a` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [1]
props.js:14:16
14| var a: number = this.props.x; // error
Expand Down Expand Up @@ -582,8 +582,8 @@ Cannot assign `this.props.z` to `c` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:319:36
319| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
Expand All @@ -604,14 +604,14 @@ References:
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props.js:20:49
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [3]
<BUILTINS>/react.js:313:36
313| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:319:36
319| number: React$PropType$Primitive<number>;
^^^^^^ [4]


Expand Down Expand Up @@ -668,8 +668,8 @@ References:
props2.js:9:41
9| getInitialState: function(): { bar: number } {
^^^^^^ [1]
<BUILTINS>/react.js:315:36
315| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:321:36
321| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props2.js:15:42
15| return <C {...this.state} foo = {0} />;
Expand All @@ -685,8 +685,8 @@ Cannot get `React.PropTypes.imaginaryType` because property `imaginaryType` is m
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:196:33
196| declare export var PropTypes: ReactPropTypes;
<BUILTINS>/react.js:202:33
202| declare export var PropTypes: ReactPropTypes;
^^^^^^^^^^^^^^ [1]


Expand All @@ -700,12 +700,12 @@ Cannot get `React.PropTypes.string.inRequired` because property `inRequired` is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:289:39
<BUILTINS>/react.js:295:39
v
289| type ReactPropsChainableTypeChecker = {
290| isRequired: ReactPropsCheckType;
291| (props: any, propName: string, componentName: string, href?: string): ?Error;
292| };
295| type ReactPropsChainableTypeChecker = {
296| isRequired: ReactPropsCheckType;
297| (props: any, propName: string, componentName: string, href?: string): ?Error;
298| };
^ [1]


Expand Down
Loading

0 comments on commit eb51ae5

Please sign in to comment.