Skip to content

Commit c3dc6c7

Browse files
committed
Finish cleaning up digest from onRecoverableError
Don't need to track it separately on the captured value anymore. Shouldn't be in the types. I used a getter for the warning instead because Proxies are kind of heavy weight options for this kind of warning. We typically use getters.
1 parent cc56bed commit c3dc6c7

File tree

4 files changed

+21
-36
lines changed

4 files changed

+21
-36
lines changed

packages/react-reconciler/src/ReactCapturedValue.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export type CapturedValue<T> = {
1717
+value: T,
1818
source: Fiber | null,
1919
stack: string | null,
20-
digest: string | null,
2120
};
2221

2322
export function createCapturedValueAtFiber<T>(
@@ -43,22 +42,19 @@ export function createCapturedValueAtFiber<T>(
4342
value,
4443
source,
4544
stack,
46-
digest: null,
4745
};
4846
}
4947

5048
export function createCapturedValueFromError(
5149
value: Error,
52-
digest: ?string,
53-
stack: ?string,
50+
stack: null | string,
5451
): CapturedValue<Error> {
5552
if (typeof stack === 'string') {
5653
CapturedStacks.set(value, stack);
5754
}
5855
return {
5956
value,
6057
source: null,
61-
stack: stack != null ? stack : null,
62-
digest: digest != null ? digest : null,
58+
stack: stack,
6359
};
6460
}

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,8 @@ function updateDehydratedSuspenseComponent(
26472647
// get an update and we'll never be able to hydrate the final content. Let's just try the
26482648
// client side render instead.
26492649
let digest: ?string;
2650-
let message, stack;
2650+
let message;
2651+
let stack = null;
26512652
if (__DEV__) {
26522653
({digest, message, stack} =
26532654
getSuspenseInstanceFallbackErrorDetails(suspenseInstance));
@@ -2670,7 +2671,10 @@ function updateDehydratedSuspenseComponent(
26702671
);
26712672
}
26722673
(error: any).digest = digest;
2673-
capturedValue = createCapturedValueFromError(error, digest, stack);
2674+
capturedValue = createCapturedValueFromError(
2675+
error,
2676+
stack === undefined ? null : stack,
2677+
);
26742678
}
26752679
return retrySuspenseComponentWithoutHydrating(
26762680
current,
@@ -2812,6 +2816,7 @@ function updateDehydratedSuspenseComponent(
28122816
'There was an error while hydrating this Suspense boundary. ' +
28132817
'Switched to client rendering.',
28142818
),
2819+
null,
28152820
);
28162821
return retrySuspenseComponentWithoutHydrating(
28172822
current,

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,37 +3121,21 @@ function commitRootImpl(
31213121
}
31223122

31233123
function makeErrorInfo(componentStack: ?string) {
3124+
const errorInfo = {
3125+
componentStack,
3126+
};
31243127
if (__DEV__) {
3125-
const errorInfo = {
3126-
componentStack,
3127-
};
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);
3128+
Object.defineProperty((errorInfo: any), 'digest', {
3129+
get() {
3130+
console.error(
3131+
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3132+
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3133+
' of the Error instance itself.',
3134+
);
31483135
},
31493136
});
3150-
} else {
3151-
return {
3152-
componentStack,
3153-
};
31543137
}
3138+
return errorInfo;
31553139
}
31563140

31573141
function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ type BaseFiberRootProperties = {
273273
) => void,
274274
onRecoverableError: (
275275
error: mixed,
276-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
276+
errorInfo: {+componentStack?: ?string},
277277
) => void,
278278

279279
formState: ReactFormState<any, any> | null,

0 commit comments

Comments
 (0)