Replaced "unstable_handleError" with "componentDidCatch" (#10200)
Ran new codemod to rename all identifiers. Searched-and-replaced strings occurrences.
Brian Vaughn committed
Jul 17, 2017 at 14:38 UTC
197e184859140524e1de92abfc6d678bbc85b340
9 files changed
+101
-101
src/renderers/__tests__/ReactErrorBoundaries-test.js
+61
-61
@@ -288,8 +288,8 @@ describe('ReactErrorBoundaries', () => {
288
componentWillUnmount() {
289
log.push('BrokenComponentWillMountErrorBoundary componentWillUnmount');
290
}
291
- unstable_handleError(error) {
292
- log.push('BrokenComponentWillMountErrorBoundary unstable_handleError');
291
+ componentDidCatch(error) {
292
+ log.push('BrokenComponentWillMountErrorBoundary componentDidCatch');
293
this.setState({error});
294
}
295
};
@@ -318,8 +318,8 @@ describe('ReactErrorBoundaries', () => {
318
componentWillUnmount() {
319
log.push('BrokenComponentDidMountErrorBoundary componentWillUnmount');
320
}
321
- unstable_handleError(error) {
322
- log.push('BrokenComponentDidMountErrorBoundary unstable_handleError');
321
+ componentDidCatch(error) {
322
+ log.push('BrokenComponentDidMountErrorBoundary componentDidCatch');
323
this.setState({error});
324
}
325
};
@@ -347,8 +347,8 @@ describe('ReactErrorBoundaries', () => {
347
componentWillUnmount() {
348
log.push('BrokenRenderErrorBoundary componentWillUnmount');
349
}
350
- unstable_handleError(error) {
351
- log.push('BrokenRenderErrorBoundary unstable_handleError');
350
+ componentDidCatch(error) {
351
+ log.push('BrokenRenderErrorBoundary componentDidCatch');
352
this.setState({error});
353
}
354
};
@@ -400,12 +400,12 @@ describe('ReactErrorBoundaries', () => {
400
componentWillUnmount() {
401
log.push('NoopErrorBoundary componentWillUnmount');
402
}
403
- unstable_handleError() {
403
+ componentDidCatch() {
404
if (ReactDOMFeatureFlags.useFiber) {
405
- log.push('NoopErrorBoundary unstable_handleError');
405
+ log.push('NoopErrorBoundary componentDidCatch');
406
} else {
407
// In Stack, not calling setState() is treated as a rethrow.
408
- log.push('NoopErrorBoundary unstable_handleError [*]');
408
+ log.push('NoopErrorBoundary componentDidCatch [*]');
409
}
410
}
411
};
@@ -456,8 +456,8 @@ describe('ReactErrorBoundaries', () => {
456
log.push(`${this.props.logName} render success`);
457
return <div>{this.props.children}</div>;
458
}
459
- unstable_handleError(error) {
460
- log.push(`${this.props.logName} unstable_handleError`);
459
+ componentDidCatch(error) {
460
+ log.push(`${this.props.logName} componentDidCatch`);
461
this.setState({error});
462
}
463
componentWillMount() {
@@ -508,13 +508,13 @@ describe('ReactErrorBoundaries', () => {
508
componentWillUnmount() {
509
log.push('RetryErrorBoundary componentWillUnmount');
510
}
511
- unstable_handleError(error) {
511
+ componentDidCatch(error) {
512
if (ReactDOMFeatureFlags.useFiber) {
513
- log.push('RetryErrorBoundary unstable_handleError [!]');
513
+ log.push('RetryErrorBoundary componentDidCatch [!]');
514
// In Fiber, calling setState() (and failing) is treated as a rethrow.
515
this.setState({});
516
} else {
517
- log.push('RetryErrorBoundary unstable_handleError [*]');
517
+ log.push('RetryErrorBoundary componentDidCatch [*]');
518
// In Stack, not calling setState() is treated as a rethrow.
519
}
520
}
@@ -646,14 +646,14 @@ describe('ReactErrorBoundaries', () => {
646
// Fiber mounts with null children before capturing error
647
'ErrorBoundary componentDidMount',
648
// Catch and render an error message
649
- 'ErrorBoundary unstable_handleError',
649
+ 'ErrorBoundary componentDidCatch',
650
'ErrorBoundary componentWillUpdate',
651
'ErrorBoundary render error',
652
'ErrorBoundary componentDidUpdate',
653
]
654
: [
655
// Catch and render an error message
656
- 'ErrorBoundary unstable_handleError',
656
+ 'ErrorBoundary componentDidCatch',
657
'ErrorBoundary render error',
658
'ErrorBoundary componentDidMount',
659
]),
@@ -683,14 +683,14 @@ describe('ReactErrorBoundaries', () => {
683
// Fiber mounts with null children before capturing error
684
'ErrorBoundary componentDidMount',
685
// Catch and render an error message
686
- 'ErrorBoundary unstable_handleError',
686
+ 'ErrorBoundary componentDidCatch',
687
'ErrorBoundary componentWillUpdate',
688
'ErrorBoundary render error',
689
'ErrorBoundary componentDidUpdate',
690
]
691
: [
692
// Catch and render an error message
693
- 'ErrorBoundary unstable_handleError',
693
+ 'ErrorBoundary componentDidCatch',
694
'ErrorBoundary render error',
695
'ErrorBoundary componentDidMount',
696
]),
@@ -719,14 +719,14 @@ describe('ReactErrorBoundaries', () => {
719
...(ReactDOMFeatureFlags.useFiber
720
? [
721
'ErrorBoundary componentDidMount',
722
- 'ErrorBoundary unstable_handleError',
722
+ 'ErrorBoundary componentDidCatch',
723
'ErrorBoundary componentWillUpdate',
724
'ErrorBoundary render error',
725
'ErrorBoundary componentDidUpdate',
726
]
727
: [
728
// Catch and render an error message
729
- 'ErrorBoundary unstable_handleError',
729
+ 'ErrorBoundary componentDidCatch',
730
'ErrorBoundary render error',
731
'ErrorBoundary componentDidMount',
732
]),
@@ -811,7 +811,7 @@ describe('ReactErrorBoundaries', () => {
811
...(ReactDOMFeatureFlags.useFiber
812
? [
813
'ErrorBoundary componentDidMount',
814
- 'ErrorBoundary unstable_handleError',
814
+ 'ErrorBoundary componentDidCatch',
815
'ErrorBoundary componentWillUpdate',
816
'ErrorBoundary render error',
817
'ErrorMessage constructor',
@@ -822,7 +822,7 @@ describe('ReactErrorBoundaries', () => {
822
]
823
: [
824
// Handle the error:
825
- 'ErrorBoundary unstable_handleError',
825
+ 'ErrorBoundary componentDidCatch',
826
'ErrorBoundary render error',
827
// Mount the error message:
828
'ErrorMessage constructor',
@@ -866,7 +866,7 @@ describe('ReactErrorBoundaries', () => {
866
? [
867
// In Fiber, failed error boundaries render null before attempting to recover
868
'RetryErrorBoundary componentDidMount',
869
- 'RetryErrorBoundary unstable_handleError [!]',
869
+ 'RetryErrorBoundary componentDidCatch [!]',
870
'ErrorBoundary componentDidMount',
871
// Retry
872
'RetryErrorBoundary render',
@@ -875,7 +875,7 @@ describe('ReactErrorBoundaries', () => {
875
'BrokenRender render [!]',
876
// This time, the error propagates to the higher boundary
877
'RetryErrorBoundary componentWillUnmount',
878
- 'ErrorBoundary unstable_handleError',
878
+ 'ErrorBoundary componentDidCatch',
879
// Render the error
880
'ErrorBoundary componentWillUpdate',
881
'ErrorBoundary render error',
@@ -884,13 +884,13 @@ describe('ReactErrorBoundaries', () => {
884
: [
885
// The first error boundary catches the error.
886
// However, it doesn't adjust its state so next render will also fail.
887
- 'RetryErrorBoundary unstable_handleError [*]',
887
+ 'RetryErrorBoundary componentDidCatch [*]',
888
'RetryErrorBoundary render',
889
'BrokenRender constructor',
890
'BrokenRender componentWillMount',
891
'BrokenRender render [!]',
892
// This time, the error propagates to the higher boundary
893
- 'ErrorBoundary unstable_handleError',
893
+ 'ErrorBoundary componentDidCatch',
894
// Render the error
895
'ErrorBoundary render error',
896
'ErrorBoundary componentDidMount',
@@ -921,13 +921,13 @@ describe('ReactErrorBoundaries', () => {
921
...(ReactDOMFeatureFlags.useFiber
922
? [
923
'ErrorBoundary componentDidMount',
924
- 'ErrorBoundary unstable_handleError',
924
+ 'ErrorBoundary componentDidCatch',
925
'ErrorBoundary componentWillUpdate',
926
'ErrorBoundary render error',
927
'ErrorBoundary componentDidUpdate',
928
]
929
: [
930
- 'ErrorBoundary unstable_handleError',
930
+ 'ErrorBoundary componentDidCatch',
931
// Render the error
932
'ErrorBoundary render error',
933
'ErrorBoundary componentDidMount',
@@ -967,22 +967,22 @@ describe('ReactErrorBoundaries', () => {
967
// Finish mounting with null children
968
'BrokenRenderErrorBoundary componentDidMount',
969
// Attempt to handle the error
970
- 'BrokenRenderErrorBoundary unstable_handleError',
970
+ 'BrokenRenderErrorBoundary componentDidCatch',
971
'ErrorBoundary componentDidMount',
972
'BrokenRenderErrorBoundary render error [!]',
973
// Boundary fails with new error, propagate to next boundary
974
'BrokenRenderErrorBoundary componentWillUnmount',
975
// Attempt to handle the error again
976
- 'ErrorBoundary unstable_handleError',
976
+ 'ErrorBoundary componentDidCatch',
977
'ErrorBoundary componentWillUpdate',
978
'ErrorBoundary render error',
979
'ErrorBoundary componentDidUpdate',
980
]
981
: [
982
- 'BrokenRenderErrorBoundary unstable_handleError',
982
+ 'BrokenRenderErrorBoundary componentDidCatch',
983
'BrokenRenderErrorBoundary render error [!]',
984
// The error propagates to the higher boundary
985
- 'ErrorBoundary unstable_handleError',
985
+ 'ErrorBoundary componentDidCatch',
986
// Render the error
987
'ErrorBoundary render error',
988
'ErrorBoundary componentDidMount',
@@ -1022,14 +1022,14 @@ describe('ReactErrorBoundaries', () => {
1022
// Finish mounting with null children
1023
'ErrorBoundary componentDidMount',
1024
// Handle the error
1025
- 'ErrorBoundary unstable_handleError',
1025
+ 'ErrorBoundary componentDidCatch',
1026
// Render the error message
1027
'ErrorBoundary componentWillUpdate',
1028
'ErrorBoundary render error',
1029
'ErrorBoundary componentDidUpdate',
1030
]
1031
: [
1032
- 'ErrorBoundary unstable_handleError',
1032
+ 'ErrorBoundary componentDidCatch',
1033
// Render the error message
1034
'ErrorBoundary render error',
1035
'ErrorBoundary componentDidMount',
@@ -1071,7 +1071,7 @@ describe('ReactErrorBoundaries', () => {
1071
// Finish mounting with null children
1072
'ErrorBoundary componentDidMount',
1073
// Handle the error
1074
- 'ErrorBoundary unstable_handleError',
1074
+ 'ErrorBoundary componentDidCatch',
1075
// Render the error message
1076
'ErrorBoundary componentWillUpdate',
1077
'ErrorBoundary render error',
@@ -1079,7 +1079,7 @@ describe('ReactErrorBoundaries', () => {
1079
'ErrorBoundary componentDidUpdate',
1080
]
1081
: [
1082
- 'ErrorBoundary unstable_handleError',
1082
+ 'ErrorBoundary componentDidCatch',
1083
// Stack reconciler resets ref on update, as it doesn't know ref was never set.
1084
// This is unnecessary, and Fiber doesn't do it:
1085
'Child ref is set to null',
@@ -1157,14 +1157,14 @@ describe('ReactErrorBoundaries', () => {
1157
'Normal componentWillUnmount',
1158
'ErrorBoundary componentDidUpdate',
1159
// Handle the error
1160
- 'ErrorBoundary unstable_handleError',
1160
+ 'ErrorBoundary componentDidCatch',
1161
// Render the error message
1162
'ErrorBoundary componentWillUpdate',
1163
'ErrorBoundary render error',
1164
'ErrorBoundary componentDidUpdate',
1165
]
1166
: [
1167
- 'ErrorBoundary unstable_handleError',
1167
+ 'ErrorBoundary componentDidCatch',
1168
// Stack unmounts first, then renders:
1169
'Normal componentWillUnmount',
1170
'ErrorBoundary render error',
@@ -1217,14 +1217,14 @@ describe('ReactErrorBoundaries', () => {
1217
'Normal componentWillUnmount',
1218
'ErrorBoundary componentDidUpdate',
1219
// Handle the error
1220
- 'ErrorBoundary unstable_handleError',
1220
+ 'ErrorBoundary componentDidCatch',
1221
// Render the error message
1222
'ErrorBoundary componentWillUpdate',
1223
'ErrorBoundary render error',
1224
'ErrorBoundary componentDidUpdate',
1225
]
1226
: [
1227
- 'ErrorBoundary unstable_handleError',
1227
+ 'ErrorBoundary componentDidCatch',
1228
// Stack unmounts first, then renders:
1229
'Normal componentWillUnmount',
1230
'ErrorBoundary render error',
@@ -1273,13 +1273,13 @@ describe('ReactErrorBoundaries', () => {
1273
'BrokenComponentWillReceiveProps componentWillUnmount',
1274
'ErrorBoundary componentDidUpdate',
1275
// Handle the error
1276
- 'ErrorBoundary unstable_handleError',
1276
+ 'ErrorBoundary componentDidCatch',
1277
'ErrorBoundary componentWillUpdate',
1278
'ErrorBoundary render error',
1279
'ErrorBoundary componentDidUpdate',
1280
]
1281
: [
1282
- 'ErrorBoundary unstable_handleError',
1282
+ 'ErrorBoundary componentDidCatch',
1283
// Stack unmounts first, then renders:
1284
'Normal componentWillUnmount',
1285
'BrokenComponentWillReceiveProps componentWillUnmount',
@@ -1329,13 +1329,13 @@ describe('ReactErrorBoundaries', () => {
1329
'BrokenComponentWillUpdate componentWillUnmount',
1330
'ErrorBoundary componentDidUpdate',
1331
// Handle the error
1332
- 'ErrorBoundary unstable_handleError',
1332
+ 'ErrorBoundary componentDidCatch',
1333
'ErrorBoundary componentWillUpdate',
1334
'ErrorBoundary render error',
1335
'ErrorBoundary componentDidUpdate',
1336
]
1337
: [
1338
- 'ErrorBoundary unstable_handleError',
1338
+ 'ErrorBoundary componentDidCatch',
1339
// Stack unmounts first, then renders:
1340
'Normal componentWillUnmount',
1341
'BrokenComponentWillUpdate componentWillUnmount',
@@ -1389,13 +1389,13 @@ describe('ReactErrorBoundaries', () => {
1389
'Normal componentWillUnmount',
1390
'ErrorBoundary componentDidUpdate',
1391
// Handle the error
1392
- 'ErrorBoundary unstable_handleError',
1392
+ 'ErrorBoundary componentDidCatch',
1393
'ErrorBoundary componentWillUpdate',
1394
'ErrorBoundary render error',
1395
'ErrorBoundary componentDidUpdate',
1396
]
1397
: [
1398
- 'ErrorBoundary unstable_handleError',
1398
+ 'ErrorBoundary componentDidCatch',
1399
// Stack unmounts first, then renders:
1400
'Normal componentWillUnmount',
1401
'ErrorBoundary render error',
@@ -1459,12 +1459,12 @@ describe('ReactErrorBoundaries', () => {
1459
'Child1 ref is set to null',
1460
'ErrorBoundary componentDidUpdate',
1461
// Handle the error
1462
- 'ErrorBoundary unstable_handleError',
1462
+ 'ErrorBoundary componentDidCatch',
1463
'ErrorBoundary componentWillUpdate',
1464
'ErrorBoundary render error',
1465
]
1466
: [
1467
- 'ErrorBoundary unstable_handleError',
1467
+ 'ErrorBoundary componentDidCatch',
1468
// Stack resets ref first, renders later
1469
'Child1 ref is set to null',
1470
'ErrorBoundary render error',
@@ -1520,7 +1520,7 @@ describe('ReactErrorBoundaries', () => {
1520
'ErrorBoundary componentDidUpdate',
1521
// Now that commit phase is done, Fiber unmounts the boundary's children
1522
'BrokenComponentWillUnmount componentWillUnmount [!]',
1523
- 'ErrorBoundary unstable_handleError',
1523
+ 'ErrorBoundary componentDidCatch',
1524
// The initial render was aborted, so
1525
// Fiber retries from the root.
1526
'ErrorBoundary componentWillUpdate',
@@ -1532,7 +1532,7 @@ describe('ReactErrorBoundaries', () => {
1532
]
1533
: [
1534
// Stack will handle error immediately
1535
- 'ErrorBoundary unstable_handleError',
1535
+ 'ErrorBoundary componentDidCatch',
1536
// Attempt to unmount previous children:
1537
'BrokenComponentWillUnmount componentWillUnmount [!]',
1538
'Normal componentWillUnmount',
@@ -1591,7 +1591,7 @@ describe('ReactErrorBoundaries', () => {
1591
'Normal componentWillUnmount',
1592
'BrokenComponentWillUnmount componentWillUnmount [!]',
1593
// Now that commit phase is done, Fiber handles errors
1594
- 'ErrorBoundary unstable_handleError',
1594
+ 'ErrorBoundary componentDidCatch',
1595
// The initial render was aborted, so
1596
// Fiber retries from the root.
1597
'ErrorBoundary componentWillUpdate',
@@ -1601,7 +1601,7 @@ describe('ReactErrorBoundaries', () => {
1601
'ErrorBoundary componentDidUpdate',
1602
]
1603
: [
1604
- 'ErrorBoundary unstable_handleError',
1604
+ 'ErrorBoundary componentDidCatch',
1605
// Attempt to unmount previous children:
1606
'Normal componentWillUnmount',
1607
'BrokenComponentWillUnmount componentWillUnmount [!]',
@@ -1670,7 +1670,7 @@ describe('ReactErrorBoundaries', () => {
1670
'OuterErrorBoundary componentDidUpdate',
1671
// Now that commit phase is done, Fiber handles errors
1672
// Only inner boundary receives the error:
1673
- 'InnerErrorBoundary unstable_handleError',
1673
+ 'InnerErrorBoundary componentDidCatch',
1674
'InnerErrorBoundary componentWillUpdate',
1675
// Render an error now
1676
'InnerErrorBoundary render error',
@@ -1680,7 +1680,7 @@ describe('ReactErrorBoundaries', () => {
1680
]
1681
: [
1682
// Stack will handle error immediately
1683
- 'InnerErrorBoundary unstable_handleError',
1683
+ 'InnerErrorBoundary componentDidCatch',
1684
'InnerErrorBoundary render error',
1685
// In stack, this was a part of the update to the
1686
// outer boundary so both lifecycles fire
@@ -1891,7 +1891,7 @@ describe('ReactErrorBoundaries', () => {
1891
1892
expect(log).toEqual([
1893
'Stateful render [!]',
1894
- 'ErrorBoundary unstable_handleError',
1894
+ 'ErrorBoundary componentDidCatch',
1895
'ErrorBoundary componentWillUpdate',
1896
'ErrorBoundary render error',
1897
'ErrorBoundary componentDidUpdate',
@@ -1945,7 +1945,7 @@ describe('ReactErrorBoundaries', () => {
1945
'BrokenComponentDidMount componentWillUnmount',
1946
'LastChild componentWillUnmount',
1947
// Handle the error
1948
- 'ErrorBoundary unstable_handleError',
1948
+ 'ErrorBoundary componentDidCatch',
1949
'ErrorBoundary componentWillUpdate',
1950
'ErrorBoundary render error',
1951
// The update has finished
@@ -1985,7 +1985,7 @@ describe('ReactErrorBoundaries', () => {
1985
'ErrorBoundary componentDidUpdate',
1986
'BrokenComponentDidUpdate componentWillUnmount',
1987
// Then, error is handled
1988
- 'ErrorBoundary unstable_handleError',
1988
+ 'ErrorBoundary componentDidCatch',
1989
'ErrorBoundary componentWillUpdate',
1990
'ErrorBoundary render error',
1991
'ErrorBoundary componentDidUpdate',
@@ -2023,7 +2023,7 @@ describe('ReactErrorBoundaries', () => {
2023
'ErrorBoundary componentDidMount',
2024
'BrokenComponentDidMountErrorBoundary componentWillUnmount',
2025
// The error propagates to the higher boundary
2026
- 'ErrorBoundary unstable_handleError',
2026
+ 'ErrorBoundary componentDidCatch',
2027
// Fiber retries from the root
2028
'ErrorBoundary componentWillUpdate',
2029
'ErrorBoundary render error',
@@ -2115,8 +2115,8 @@ describe('ReactErrorBoundaries', () => {
2115
// were captured
2116
'BrokenComponentDidUpdate componentWillUnmount',
2117
'BrokenComponentDidUpdate componentWillUnmount',
2118
- 'InnerUnmountBoundary unstable_handleError',
2119
- 'InnerUpdateBoundary unstable_handleError',
2118
+ 'InnerUnmountBoundary componentDidCatch',
2119
+ 'InnerUpdateBoundary componentDidCatch',
2120
'InnerUnmountBoundary componentWillUpdate',
2121
'InnerUnmountBoundary render error',
2122
'InnerUpdateBoundary componentWillUpdate',
@@ -2180,7 +2180,7 @@ describe('ReactErrorBoundaries', () => {
2180
'BrokenRender render [!]',
2181
// In Fiber, noop error boundaries render null
2182
'NoopErrorBoundary componentDidMount',
2183
- 'NoopErrorBoundary unstable_handleError',
2183
+ 'NoopErrorBoundary componentDidCatch',
2184
// Nothing happens.
2185
]);
2186
src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
+2
-2
@@ -619,7 +619,7 @@ describe('ReactDOMFiber', () => {
619
620
class ErrorBoundary extends React.Component {
621
state = {error: null};
622
- unstable_handleError(error) {
622
+ componentDidCatch(error) {
623
this.setState({error});
624
}
625
render() {
@@ -652,7 +652,7 @@ describe('ReactDOMFiber', () => {
652
653
class ErrorBoundary extends React.Component {
654
state = {error: null};
655
- unstable_handleError(error) {
655
+ componentDidCatch(error) {
656
this.setState({error});
657
}
658
render() {
src/renderers/shared/fiber/ReactFiberErrorLogger.js
+1
-1
@@ -74,7 +74,7 @@ function logCapturedError(capturedError: CapturedError): void {
74
`Recreating the tree from scratch failed so React will unmount the tree.`;
75
}
76
} else {
77
- // TODO Link to unstable_handleError() documentation once it exists.
77
+ // TODO Link to componentDidCatch() documentation once it exists.
78
errorBoundaryMessage =
79
'Consider adding an error boundary to your tree to customize error handling behavior.';
80
}
src/renderers/shared/fiber/ReactFiberScheduler.js
+3
-3
@@ -216,7 +216,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
216
let isCallbackScheduled: boolean = false;
217
218
// Keep track of which fibers have captured an error that need to be handled.
219
- // Work is removed from this collection after unstable_handleError is called.
219
+ // Work is removed from this collection after componentDidCatch is called.
220
let capturedErrors: Map<Fiber, CapturedError> | null = null;
221
// Keep track of which fibers have failed during the current batch of work.
222
// This is a different set than capturedErrors, because it is not reset until
@@ -1054,7 +1054,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
1054
while (node !== null && boundary === null) {
1055
if (node.tag === ClassComponent) {
1056
const instance = node.stateNode;
1057
- if (typeof instance.unstable_handleError === 'function') {
1057
+ if (typeof instance.componentDidCatch === 'function') {
1058
errorBoundaryFound = true;
1059
errorBoundaryName = getComponentName(node);
1060
@@ -1210,7 +1210,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
1210
1211
// Allow the boundary to handle the error, usually by scheduling
1212
// an update to itself
1213
- instance.unstable_handleError(error, info);
1213
+ instance.componentDidCatch(error, info);
1214
return;
1215
case HostRoot:
1216
if (firstUncaughtError === null) {
src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
+1
-1
@@ -2257,7 +2257,7 @@ describe('ReactIncremental', () => {
2257
2258
it('maintains the correct context when unwinding due to an error in render', () => {
2259
class Root extends React.Component {
2260
- unstable_handleError(error) {
2260
+ componentDidCatch(error) {
2261
// If context is pushed/popped correctly,
2262
// This method will be used to handle the intentionally-thrown Error.
2263
}
src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
+27
-27
@@ -38,7 +38,7 @@ describe('ReactIncrementalErrorHandling', () => {
38
it('catches render error in a boundary during full deferred mounting', () => {
39
class ErrorBoundary extends React.Component {
40
state = {error: null};
41
- unstable_handleError(error) {
41
+ componentDidCatch(error) {
42
this.setState({error});
43
}
44
render() {
@@ -68,8 +68,8 @@ describe('ReactIncrementalErrorHandling', () => {
68
var ops = [];
69
class ErrorBoundary extends React.Component {
70
state = {error: null};
71
- unstable_handleError(error) {
72
- ops.push('ErrorBoundary unstable_handleError');
71
+ componentDidCatch(error) {
72
+ ops.push('ErrorBoundary componentDidCatch');
73
this.setState({error});
74
}
75
render() {
@@ -103,7 +103,7 @@ describe('ReactIncrementalErrorHandling', () => {
103
ReactNoop.flushDeferredPri(30);
104
expect(ops).toEqual([
105
'BrokenRender',
106
- 'ErrorBoundary unstable_handleError',
106
+ 'ErrorBoundary componentDidCatch',
107
'ErrorBoundary render error',
108
]);
109
expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello.')]);
@@ -113,8 +113,8 @@ describe('ReactIncrementalErrorHandling', () => {
113
var ops = [];
114
class ErrorBoundary extends React.Component {
115
state = {error: null};
116
- unstable_handleError(error) {
117
- ops.push('ErrorBoundary unstable_handleError');
116
+ componentDidCatch(error) {
117
+ ops.push('ErrorBoundary componentDidCatch');
118
this.setState({error});
119
}
120
render() {
@@ -145,7 +145,7 @@ describe('ReactIncrementalErrorHandling', () => {
145
expect(ops).toEqual([
146
'ErrorBoundary render success',
147
'BrokenRender',
148
- 'ErrorBoundary unstable_handleError',
148
+ 'ErrorBoundary componentDidCatch',
149
'ErrorBoundary render error',
150
]);
151
expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello.')]);
@@ -155,8 +155,8 @@ describe('ReactIncrementalErrorHandling', () => {
155
var ops = [];
156
class ErrorBoundary extends React.Component {
157
state = {error: null};
158
- unstable_handleError(error) {
159
- ops.push('ErrorBoundary unstable_handleError');
158
+ componentDidCatch(error) {
159
+ ops.push('ErrorBoundary componentDidCatch');
160
this.setState({error});
161
}
162
render() {
@@ -194,7 +194,7 @@ describe('ReactIncrementalErrorHandling', () => {
194
expect(ops).toEqual([
195
'ErrorBoundary render success',
196
'BrokenRender',
197
- 'ErrorBoundary unstable_handleError',
197
+ 'ErrorBoundary componentDidCatch',
198
'ErrorBoundary render error',
199
]);
200
expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello.')]);
@@ -203,8 +203,8 @@ describe('ReactIncrementalErrorHandling', () => {
203
it('propagates an error from a noop error boundary during full deferred mounting', () => {
204
var ops = [];
205
class RethrowErrorBoundary extends React.Component {
206
- unstable_handleError(error) {
207
- ops.push('RethrowErrorBoundary unstable_handleError');
206
+ componentDidCatch(error) {
207
+ ops.push('RethrowErrorBoundary componentDidCatch');
208
throw error;
209
}
210
render() {
@@ -230,7 +230,7 @@ describe('ReactIncrementalErrorHandling', () => {
230
expect(ops).toEqual([
231
'RethrowErrorBoundary render',
232
'BrokenRender',
233
- 'RethrowErrorBoundary unstable_handleError',
233
+ 'RethrowErrorBoundary componentDidCatch',
234
]);
235
expect(ReactNoop.getChildren()).toEqual([]);
236
});
@@ -238,8 +238,8 @@ describe('ReactIncrementalErrorHandling', () => {
238
it('propagates an error from a noop error boundary during partial deferred mounting', () => {
239
var ops = [];
240
class RethrowErrorBoundary extends React.Component {
241
- unstable_handleError(error) {
242
- ops.push('RethrowErrorBoundary unstable_handleError');
241
+ componentDidCatch(error) {
242
+ ops.push('RethrowErrorBoundary componentDidCatch');
243
throw error;
244
}
245
render() {
@@ -268,7 +268,7 @@ describe('ReactIncrementalErrorHandling', () => {
268
}).toThrow('Hello');
269
expect(ops).toEqual([
270
'BrokenRender',
271
- 'RethrowErrorBoundary unstable_handleError',
271
+ 'RethrowErrorBoundary componentDidCatch',
272
]);
273
expect(ReactNoop.getChildren()).toEqual([]);
274
});
@@ -276,8 +276,8 @@ describe('ReactIncrementalErrorHandling', () => {
276
it('propagates an error from a noop error boundary during synchronous mounting', () => {
277
var ops = [];
278
class RethrowErrorBoundary extends React.Component {
279
- unstable_handleError(error) {
280
- ops.push('RethrowErrorBoundary unstable_handleError');
279
+ componentDidCatch(error) {
280
+ ops.push('RethrowErrorBoundary componentDidCatch');
281
throw error;
282
}
283
render() {
@@ -303,7 +303,7 @@ describe('ReactIncrementalErrorHandling', () => {
303
expect(ops).toEqual([
304
'RethrowErrorBoundary render',
305
'BrokenRender',
306
- 'RethrowErrorBoundary unstable_handleError',
306
+ 'RethrowErrorBoundary componentDidCatch',
307
]);
308
expect(ReactNoop.getChildren()).toEqual([]);
309
});
@@ -311,8 +311,8 @@ describe('ReactIncrementalErrorHandling', () => {
311
it('propagates an error from a noop error boundary during batched mounting', () => {
312
var ops = [];
313
class RethrowErrorBoundary extends React.Component {
314
- unstable_handleError(error) {
315
- ops.push('RethrowErrorBoundary unstable_handleError');
314
+ componentDidCatch(error) {
315
+ ops.push('RethrowErrorBoundary componentDidCatch');
316
throw error;
317
}
318
render() {
@@ -345,7 +345,7 @@ describe('ReactIncrementalErrorHandling', () => {
345
expect(ops).toEqual([
346
'RethrowErrorBoundary render',
347
'BrokenRender',
348
- 'RethrowErrorBoundary unstable_handleError',
348
+ 'RethrowErrorBoundary componentDidCatch',
349
]);
350
expect(ReactNoop.getChildren()).toEqual([]);
351
});
@@ -485,7 +485,7 @@ describe('ReactIncrementalErrorHandling', () => {
485
it('continues work on other roots despite caught errors', () => {
486
class ErrorBoundary extends React.Component {
487
state = {error: null};
488
- unstable_handleError(error) {
488
+ componentDidCatch(error) {
489
this.setState({error});
490
}
491
render() {
@@ -627,7 +627,7 @@ describe('ReactIncrementalErrorHandling', () => {
627
628
class Boundary extends React.Component {
629
state = {error: null};
630
- unstable_handleError(error) {
630
+ componentDidCatch(error) {
631
this.setState({error});
632
}
633
render() {
@@ -662,7 +662,7 @@ describe('ReactIncrementalErrorHandling', () => {
662
663
class ErrorBoundary extends React.Component {
664
state = {error: null};
665
- unstable_handleError(error) {
665
+ componentDidCatch(error) {
666
this.setState({error});
667
}
668
render() {
@@ -699,7 +699,7 @@ describe('ReactIncrementalErrorHandling', () => {
699
700
class ErrorBoundary extends React.Component {
701
state = {error: null};
702
- unstable_handleError(error) {
702
+ componentDidCatch(error) {
703
this.setState({error});
704
}
705
render() {
@@ -1002,7 +1002,7 @@ describe('ReactIncrementalErrorHandling', () => {
1002
let renderAttempts = 0;
1003
1004
class ErrorBoundaryComponent extends React.Component {
1005
- unstable_handleError(error) {
1005
+ componentDidCatch(error) {
1006
handleErrorCalls.push(error);
1007
this.setState({}); // Render again
1008
}
src/renderers/shared/fiber/__tests__/ReactIncrementalPerf-test.js
+1
-1
@@ -357,7 +357,7 @@ describe('ReactDebugFiberPerf', () => {
357
358
class Boundary extends React.Component {
359
state = {error: null};
360
- unstable_handleError(error) {
360
+ componentDidCatch(error) {
361
this.setState({error});
362
}
363
render() {
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+4
-4
@@ -352,7 +352,7 @@ var ReactCompositeComponent = {
352
}
353
354
var markup;
355
- if (inst.unstable_handleError) {
355
+ if (inst.componentDidCatch) {
356
markup = this.performInitialMountWithErrorHandling(
357
renderedElement,
358
hostParent,
@@ -480,7 +480,7 @@ var ReactCompositeComponent = {
480
} catch (e) {
481
// Roll back to checkpoint, handle error (which may add items to the transaction), and take a new checkpoint
482
transaction.rollback(checkpoint);
483
- this._instance.unstable_handleError(e);
483
+ this._instance.componentDidCatch(e);
484
if (this._pendingStateQueue) {
485
this._instance.state = this._processPendingState(
486
this._instance.props,
@@ -1049,7 +1049,7 @@ var ReactCompositeComponent = {
1049
inst.state = nextState;
1050
inst.context = nextContext;
1051
1052
- if (inst.unstable_handleError) {
1052
+ if (inst.componentDidCatch) {
1053
this._updateRenderedComponentWithErrorHandling(
1054
transaction,
1055
unmaskedContext,
@@ -1092,7 +1092,7 @@ var ReactCompositeComponent = {
1092
// Roll back to checkpoint, handle error (which may add items to the transaction),
1093
// and take a new checkpoint
1094
transaction.rollback(checkpoint);
1095
- this._instance.unstable_handleError(e);
1095
+ this._instance.componentDidCatch(e);
1096
if (this._pendingStateQueue) {
1097
this._instance.state = this._processPendingState(
1098
this._instance.props,
src/renderers/testing/__tests__/ReactTestRenderer-test.js
+1
-1
@@ -439,7 +439,7 @@ describe('ReactTestRenderer', () => {
439
onClick() {
440
/* do nothing */
441
}
442
- unstable_handleError() {
442
+ componentDidCatch() {
443
this.setState({error: true});
444
}
445
}