Skip to content

Commit

Permalink
Renamed getDerivedStateFromCatch -> getDerivedStateFromError
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Sep 27, 2018
1 parent 99d6d02 commit a18bc9f
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 75 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ function finishClassComponent(
let nextChildren;
if (
didCaptureError &&
typeof Component.getDerivedStateFromCatch !== 'function'
typeof Component.getDerivedStateFromError !== 'function'
) {
// If we captured an error, but getDerivedStateFrom catch is not defined,
// unmount all the children. componentDidCatch will schedule an update to
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
name,
);
const noInstanceGetDerivedStateFromCatch =
typeof instance.getDerivedStateFromCatch !== 'function';
typeof instance.getDerivedStateFromError !== 'function';
warningWithoutStack(
noInstanceGetDerivedStateFromCatch,
'%s: getDerivedStateFromCatch() is defined as an instance method ' +
'%s: getDerivedStateFromError() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
name,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ function dispatch(
const ctor = fiber.type;
const instance = fiber.stateNode;
if (
typeof ctor.getDerivedStateFromCatch === 'function' ||
typeof ctor.getDerivedStateFromError === 'function' ||
(typeof instance.componentDidCatch === 'function' &&
!isAlreadyFailedLegacyErrorBoundary(instance))
) {
Expand Down
12 changes: 6 additions & 6 deletions packages/react-reconciler/src/ReactFiberUnwindWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ function createClassErrorUpdate(
): Update<mixed> {
const update = createUpdate(expirationTime);
update.tag = CaptureUpdate;
const getDerivedStateFromCatch = fiber.type.getDerivedStateFromCatch;
if (typeof getDerivedStateFromCatch === 'function') {
const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
if (typeof getDerivedStateFromError === 'function') {
const error = errorInfo.value;
update.payload = () => {
return getDerivedStateFromCatch(error);
return getDerivedStateFromError(error);
};
}

const inst = fiber.stateNode;
if (inst !== null && typeof inst.componentDidCatch === 'function') {
update.callback = function callback() {
if (getDerivedStateFromCatch !== 'function') {
if (getDerivedStateFromError !== 'function') {
// To preserve the preexisting retry behavior of error boundaries,
// we keep track of which ones already failed during this batch.
// This gets reset before we yield back to the browser.
// TODO: Warn in strict mode if getDerivedStateFromCatch is
// TODO: Warn in strict mode if getDerivedStateFromError is
// not defined.
markLegacyErrorBoundaryAsFailed(this);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ function throwException(
const instance = workInProgress.stateNode;
if (
(workInProgress.effectTag & DidCapture) === NoEffect &&
(typeof ctor.getDerivedStateFromCatch === 'function' ||
(typeof ctor.getDerivedStateFromError === 'function' ||
(instance !== null &&
typeof instance.componentDidCatch === 'function' &&
!isAlreadyFailedLegacyErrorBoundary(instance)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ErrorBoundaryReconciliation', () => {

GetDerivedErrorBoundary = class extends React.Component {
state = {error: null};
static getDerivedStateFromCatch(error) {
static getDerivedStateFromError(error) {
return {error};
}
render() {
Expand Down Expand Up @@ -101,10 +101,10 @@ describe('ErrorBoundaryReconciliation', () => {
it('componentDidCatch can recover by rendering an element of a different type', () =>
sharedTest(DidCatchErrorBoundary, 'div'));

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

it('getDerivedStateFromCatch can recover by rendering an element of a different type', () =>
it('getDerivedStateFromError can recover by rendering an element of a different type', () =>
sharedTest(GetDerivedErrorBoundary, 'div'));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,10 +1441,10 @@ describe('ReactIncrementalErrorHandling', () => {
]);
});

it('does not provide component stack to the error boundary with getDerivedStateFromCatch', () => {
it('does not provide component stack to the error boundary with getDerivedStateFromError', () => {
class ErrorBoundary extends React.Component {
state = {error: null};
static getDerivedStateFromCatch(error, errorInfo) {
static getDerivedStateFromError(error, errorInfo) {
expect(errorInfo).toBeUndefined();
return {error};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ describe 'ReactCoffeeScriptClass', ->
).toWarnDev 'Foo: getDerivedStateFromProps() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
undefined

it 'warns if getDerivedStateFromCatch is not static', ->
it 'warns if getDerivedStateFromError is not static', ->
class Foo extends React.Component
render: ->
div()
getDerivedStateFromCatch: ->
getDerivedStateFromError: ->
{}
expect(->
ReactDOM.render(React.createElement(Foo, foo: 'foo'), container)
).toWarnDev 'Foo: getDerivedStateFromCatch() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
).toWarnDev 'Foo: getDerivedStateFromError() is defined as an instance method and will be ignored. Instead, declare it as a static method.', {withoutStack: true}
undefined

it 'warns if getSnapshotBeforeUpdate is static', ->
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/__tests__/ReactES6Class-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ describe('ReactES6Class', () => {
);
});

it('warns if getDerivedStateFromCatch is not static', () => {
it('warns if getDerivedStateFromError is not static', () => {
class Foo extends React.Component {
getDerivedStateFromCatch() {
getDerivedStateFromError() {
return {};
}
render() {
return <div />;
}
}
expect(() => ReactDOM.render(<Foo foo="foo" />, container)).toWarnDev(
'Foo: getDerivedStateFromCatch() is defined as an instance method ' +
'Foo: getDerivedStateFromError() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
{withoutStack: true},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ describe('Profiler', () => {
);
});

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

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

class ErrorBoundary extends React.Component {
state = {error: null};
static getDerivedStateFromCatch(error) {
static getDerivedStateFromError(error) {
return {error};
}
render() {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/__tests__/ReactTypeScriptClass-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ describe('ReactTypeScriptClass', function() {
);
});

it('warns if getDerivedStateFromCatch is not static', function() {
it('warns if getDerivedStateFromError is not static', function() {
class Foo extends React.Component {
getDerivedStateFromCatch() {
getDerivedStateFromError() {
return {};
}
render() {
Expand All @@ -409,7 +409,7 @@ describe('ReactTypeScriptClass', function() {
expect(function() {
ReactDOM.render(React.createElement(Foo, {foo: 'foo'}), container);
}).toWarnDev(
'Foo: getDerivedStateFromCatch() is defined as an instance method ' +
'Foo: getDerivedStateFromError() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
{withoutStack: true}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ describe('create-react-class-integration', () => {
);
});

it('warns if getDerivedStateFromCatch is not static', () => {
it('warns if getDerivedStateFromError is not static', () => {
const Foo = createReactClass({
getDerivedStateFromCatch() {
getDerivedStateFromError() {
return {};
},
render() {
Expand All @@ -471,7 +471,7 @@ describe('create-react-class-integration', () => {
expect(() =>
ReactDOM.render(<Foo foo="foo" />, document.createElement('div')),
).toWarnDev(
'Component: getDerivedStateFromCatch() is defined as an instance method ' +
'Component: getDerivedStateFromError() is defined as an instance method ' +
'and will be ignored. Instead, declare it as a static method.',
{withoutStack: true},
);
Expand Down

0 comments on commit a18bc9f

Please sign in to comment.