Skip to content

Commit 6000fee

Browse files
committed
Removes the digest property from errorInfo passed to onRecoverableError when handling an error propagated from the server. Previously we warned in Dev but still provided the digest on the errorInfo object. This change removes digest from error info but continues to warn if it is accessed. The reason for retaining the warning is the version with the warning was not released as stable but we will include this deprecated removal in our next major so we should communicate this change at runtime.
1 parent 2efa383 commit 6000fee

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3621,11 +3621,11 @@ describe('ReactDOMFizzServer', () => {
36213621
onRecoverableError(error, errorInfo) {
36223622
expect(() => {
36233623
expect(error.digest).toBe('a digest');
3624-
expect(errorInfo.digest).toBe('a digest');
3624+
expect(errorInfo.digest).toBe(undefined);
36253625
}).toErrorDev(
3626-
'Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3627-
' This property is deprecated and will be removed in a future version of React.' +
3628-
' To access the digest of an Error look for this property on the Error instance itself.',
3626+
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3627+
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3628+
' of the Error instance itself.',
36293629
{withoutStack: true},
36303630
);
36313631
},

packages/react-reconciler/src/ReactFiberWorkLoop.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -3001,10 +3001,7 @@ function commitRootImpl(
30013001
const onRecoverableError = root.onRecoverableError;
30023002
for (let i = 0; i < recoverableErrors.length; i++) {
30033003
const recoverableError = recoverableErrors[i];
3004-
const errorInfo = makeErrorInfo(
3005-
recoverableError.digest,
3006-
recoverableError.stack,
3007-
);
3004+
const errorInfo = makeErrorInfo(recoverableError.stack);
30083005
onRecoverableError(recoverableError.value, errorInfo);
30093006
}
30103007
}
@@ -3104,28 +3101,35 @@ function commitRootImpl(
31043101
return null;
31053102
}
31063103

3107-
function makeErrorInfo(digest: ?string, componentStack: ?string) {
3104+
function makeErrorInfo(componentStack: ?string) {
31083105
if (__DEV__) {
31093106
const errorInfo = {
31103107
componentStack,
3111-
digest,
31123108
};
3113-
Object.defineProperty(errorInfo, 'digest', {
3114-
configurable: false,
3115-
enumerable: true,
3116-
get() {
3117-
console.error(
3118-
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3119-
' This property is deprecated and will be removed in a future version of React.' +
3120-
' To access the digest of an Error look for this property on the Error instance itself.',
3121-
);
3122-
return digest;
3109+
return new Proxy(errorInfo, {
3110+
get(target, prop, receiver) {
3111+
if (prop === 'digest') {
3112+
console.error(
3113+
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3114+
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3115+
' of the Error instance itself.',
3116+
);
3117+
}
3118+
return Reflect.get(target, prop, receiver);
3119+
},
3120+
has(target, prop) {
3121+
if (prop === 'digest') {
3122+
console.error(
3123+
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3124+
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3125+
' of the Error instance itself.',
3126+
);
3127+
}
3128+
return Reflect.has(target, prop);
31233129
},
31243130
});
3125-
return errorInfo;
31263131
} else {
31273132
return {
3128-
digest,
31293133
componentStack,
31303134
};
31313135
}

0 commit comments

Comments
 (0)