@samitouri / QOS-React-2 / commits / 299a9c0598

[Fiber] Remove the digest property from errorInfo passed to onRecoverableError (#28222)

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.

Josh Story committed Mar 28, 2024 at 08:01 UTC 299a9c0598576f7dba170771b1c0b821281b1e15
2 files changed +26 -22
packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
+4 -4
@@ -3563,11 +3563,11 @@ describe('ReactDOMFizzServer', () => {
3563 onRecoverableError(error, errorInfo) {
3564 expect(() => {
3565 expect(error.digest).toBe('a digest');
3566 - expect(errorInfo.digest).toBe('a digest');
3566 + expect(errorInfo.digest).toBe(undefined);
3567 }).toErrorDev(
3568 - 'Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3569 - ' This property is deprecated and will be removed in a future version of React.' +
3570 - ' To access the digest of an Error look for this property on the Error instance itself.',
3568 + 'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3569 + ' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3570 + ' of the Error instance itself.',
3571 {withoutStack: true},
3572 );
3573 },
packages/react-reconciler/src/ReactFiberWorkLoop.js
+22 -18
@@ -3022,10 +3022,7 @@ function commitRootImpl(
3022 const onRecoverableError = root.onRecoverableError;
3023 for (let i = 0; i < recoverableErrors.length; i++) {
3024 const recoverableError = recoverableErrors[i];
3025 - const errorInfo = makeErrorInfo(
3026 - recoverableError.digest,
3027 - recoverableError.stack,
3028 - );
3025 + const errorInfo = makeErrorInfo(recoverableError.stack);
3026 onRecoverableError(recoverableError.value, errorInfo);
3027 }
3028 }
@@ -3123,28 +3120,35 @@ function commitRootImpl(
3120 return null;
3121 }
3122
3126 -function makeErrorInfo(digest: ?string, componentStack: ?string) {
3123 +function makeErrorInfo(componentStack: ?string) {
3124 if (__DEV__) {
3125 const errorInfo = {
3126 componentStack,
3130 - digest,
3127 };
3132 - Object.defineProperty(errorInfo, 'digest', {
3133 - configurable: false,
3134 - enumerable: true,
3135 - get() {
3136 - console.error(
3137 - 'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3138 - ' This property is deprecated and will be removed in a future version of React.' +
3139 - ' To access the digest of an Error look for this property on the Error instance itself.',
3140 - );
3141 - return digest;
3128 + return new Proxy(errorInfo, {
3129 + get(target, prop, receiver) {
3130 + if (prop === 'digest') {
3131 + console.error(
3132 + 'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3133 + ' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3134 + ' of the Error instance itself.',
3135 + );
3136 + }
3137 + return Reflect.get(target, prop, receiver);
3138 + },
3139 + has(target, prop) {
3140 + if (prop === 'digest') {
3141 + console.error(
3142 + 'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3143 + ' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3144 + ' of the Error instance itself.',
3145 + );
3146 + }
3147 + return Reflect.has(target, prop);
3148 },
3149 });
3144 - return errorInfo;
3150 } else {
3151 return {
3147 - digest,
3152 componentStack,
3153 };
3154 }