Skip to content

Commit a18bc9f

Browse files
author
Brian Vaughn
committed
Renamed getDerivedStateFromCatch -> getDerivedStateFromError
1 parent 99d6d02 commit a18bc9f

12 files changed

+75
-75
lines changed

packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js

Lines changed: 46 additions & 46 deletions
Large diffs are not rendered by default.

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ function finishClassComponent(
388388
let nextChildren;
389389
if (
390390
didCaptureError &&
391-
typeof Component.getDerivedStateFromCatch !== 'function'
391+
typeof Component.getDerivedStateFromError !== 'function'
392392
) {
393393
// If we captured an error, but getDerivedStateFrom catch is not defined,
394394
// unmount all the children. componentDidCatch will schedule an update to

packages/react-reconciler/src/ReactFiberClassComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
466466
name,
467467
);
468468
const noInstanceGetDerivedStateFromCatch =
469-
typeof instance.getDerivedStateFromCatch !== 'function';
469+
typeof instance.getDerivedStateFromError !== 'function';
470470
warningWithoutStack(
471471
noInstanceGetDerivedStateFromCatch,
472-
'%s: getDerivedStateFromCatch() is defined as an instance method ' +
472+
'%s: getDerivedStateFromError() is defined as an instance method ' +
473473
'and will be ignored. Instead, declare it as a static method.',
474474
name,
475475
);

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ function dispatch(
14641464
const ctor = fiber.type;
14651465
const instance = fiber.stateNode;
14661466
if (
1467-
typeof ctor.getDerivedStateFromCatch === 'function' ||
1467+
typeof ctor.getDerivedStateFromError === 'function' ||
14681468
(typeof instance.componentDidCatch === 'function' &&
14691469
!isAlreadyFailedLegacyErrorBoundary(instance))
14701470
) {

packages/react-reconciler/src/ReactFiberUnwindWork.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ function createClassErrorUpdate(
100100
): Update<mixed> {
101101
const update = createUpdate(expirationTime);
102102
update.tag = CaptureUpdate;
103-
const getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch;
104-
if (typeof getDerivedStateFromCatch === 'function') {
103+
const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
104+
if (typeof getDerivedStateFromError === 'function') {
105105
const error = errorInfo.value;
106106
update.payload = () => {
107-
return getDerivedStateFromCatch(error);
107+
return getDerivedStateFromError(error);
108108
};
109109
}
110110

111111
const inst = fiber.stateNode;
112112
if (inst !== null && typeof inst.componentDidCatch === 'function') {
113113
update.callback = function callback() {
114-
if (getDerivedStateFromCatch !== 'function') {
114+
if (getDerivedStateFromError !== 'function') {
115115
// To preserve the preexisting retry behavior of error boundaries,
116116
// we keep track of which ones already failed during this batch.
117117
// This gets reset before we yield back to the browser.
118-
// TODO: Warn in strict mode if getDerivedStateFromCatch is
118+
// TODO: Warn in strict mode if getDerivedStateFromError is
119119
// not defined.
120120
markLegacyErrorBoundaryAsFailed(this);
121121
}
@@ -354,7 +354,7 @@ function throwException(
354354
const instance = workInProgress.stateNode;
355355
if (
356356
(workInProgress.effectTag & DidCapture) === NoEffect &&
357-
(typeof ctor.getDerivedStateFromCatch === 'function' ||
357+
(typeof ctor.getDerivedStateFromError === 'function' ||
358358
(instance !== null &&
359359
typeof instance.componentDidCatch === 'function' &&
360360
!isAlreadyFailedLegacyErrorBoundary(instance)))

packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('ErrorBoundaryReconciliation', () => {
3333

3434
GetDerivedErrorBoundary = class extends React.Component {
3535
state = {error: null};
36-
static getDerivedStateFromCatch(error) {
36+
static getDerivedStateFromError(error) {
3737
return {error};
3838
}
3939
render() {
@@ -101,10 +101,10 @@ describe('ErrorBoundaryReconciliation', () => {
101101
it('componentDidCatch can recover by rendering an element of a different type', () =>
102102
sharedTest(DidCatchErrorBoundary, 'div'));
103103

104-
it('getDerivedStateFromCatch can recover by rendering an element of the same type', () =>
104+
it('getDerivedStateFromError can recover by rendering an element of the same type', () =>
105105
sharedTest(GetDerivedErrorBoundary, 'span'));
106106

107-
it('getDerivedStateFromCatch can recover by rendering an element of a different type', () =>
107+
it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
108108
sharedTest(GetDerivedErrorBoundary, 'div'));
109109
});
110110
});

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,10 @@ describe('ReactIncrementalErrorHandling', () => {
14411441
]);
14421442
});
14431443

1444-
it('does not provide component stack to the error boundary with getDerivedStateFromCatch', () => {
1444+
it('does not provide component stack to the error boundary with getDerivedStateFromError', () => {
14451445
class ErrorBoundary extends React.Component {
14461446
state = {error: null};
1447-
static getDerivedStateFromCatch(error, errorInfo) {
1447+
static getDerivedStateFromError(error, errorInfo) {
14481448
expect(errorInfo).toBeUndefined();
14491449
return {error};
14501450
}

packages/react/src/__tests__/ReactCoffeeScriptClass-test.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ describe 'ReactCoffeeScriptClass', ->
129129
).toWarnDev 'Foo: getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
130130
undefined
131131

132-
it 'warns if getDerivedStateFromCatch is not static', ->
132+
it 'warns if getDerivedStateFromError is not static', ->
133133
class Foo extends React.Component
134134
render: ->
135135
div()
136-
getDerivedStateFromCatch: ->
136+
getDerivedStateFromError: ->
137137
{}
138138
expect(->
139139
ReactDOM.render(React.createElement(Foo, foo: 'foo'), container)
140-
).toWarnDev 'Foo: getDerivedStateFromCatch() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
140+
).toWarnDev 'Foo: getDerivedStateFromError() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
141141
undefined
142142

143143
it 'warns if getSnapshotBeforeUpdate is static', ->

packages/react/src/__tests__/ReactES6Class-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ describe('ReactES6Class', () => {
147147
);
148148
});
149149

150-
it('warns if getDerivedStateFromCatch is not static', () => {
150+
it('warns if getDerivedStateFromError is not static', () => {
151151
class Foo extends React.Component {
152-
getDerivedStateFromCatch() {
152+
getDerivedStateFromError() {
153153
return {};
154154
}
155155
render() {
156156
return <div />;
157157
}
158158
}
159159
expect(() => ReactDOM.render(<Foo foo="foo" />, container)).toWarnDev(
160-
'Foo: getDerivedStateFromCatch() is defined as an instance method ' +
160+
'Foo: getDerivedStateFromError() is defined as an instance method ' +
161161
'and will be ignored. Instead, declare it as a static method.',
162162
{withoutStack: true},
163163
);

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ describe('Profiler', () => {
984984
);
985985
});
986986

987-
it('should accumulate actual time after an error handled by getDerivedStateFromCatch()', () => {
987+
it('should accumulate actual time after an error handled by getDerivedStateFromError()', () => {
988988
const callback = jest.fn();
989989

990990
const ThrowsError = () => {
@@ -994,7 +994,7 @@ describe('Profiler', () => {
994994

995995
class ErrorBoundary extends React.Component {
996996
state = {error: null};
997-
static getDerivedStateFromCatch(error) {
997+
static getDerivedStateFromError(error) {
998998
return {error};
999999
}
10001000
render() {

packages/react/src/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ describe('ReactTypeScriptClass', function() {
397397
);
398398
});
399399

400-
it('warns if getDerivedStateFromCatch is not static', function() {
400+
it('warns if getDerivedStateFromError is not static', function() {
401401
class Foo extends React.Component {
402-
getDerivedStateFromCatch() {
402+
getDerivedStateFromError() {
403403
return {};
404404
}
405405
render() {
@@ -409,7 +409,7 @@ describe('ReactTypeScriptClass', function() {
409409
expect(function() {
410410
ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container);
411411
}).toWarnDev(
412-
'Foo: getDerivedStateFromCatch() is defined as an instance method ' +
412+
'Foo: getDerivedStateFromError() is defined as an instance method ' +
413413
'and will be ignored. Instead, declare it as a static method.',
414414
{withoutStack: true}
415415
);

packages/react/src/__tests__/createReactClassIntegration-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ describe('create-react-class-integration', () => {
459459
);
460460
});
461461

462-
it('warns if getDerivedStateFromCatch is not static', () => {
462+
it('warns if getDerivedStateFromError is not static', () => {
463463
const Foo = createReactClass({
464-
getDerivedStateFromCatch() {
464+
getDerivedStateFromError() {
465465
return {};
466466
},
467467
render() {
@@ -471,7 +471,7 @@ describe('create-react-class-integration', () => {
471471
expect(() =>
472472
ReactDOM.render(<Foo foo="foo" />, document.createElement('div')),
473473
).toWarnDev(
474-
'Component: getDerivedStateFromCatch() is defined as an instance method ' +
474+
'Component: getDerivedStateFromError() is defined as an instance method ' +
475475
'and will be ignored. Instead, declare it as a static method.',
476476
{withoutStack: true},
477477
);

0 commit comments

Comments
 (0)