Skip to content

Commit df95577

Browse files
authored
Finish cleaning up digest from onRecoverableError (#28686)
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 9f835e6 commit df95577

File tree

8 files changed

+25
-43
lines changed

8 files changed

+25
-43
lines changed

packages/react-dom/src/client/ReactDOMRoot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type CreateRootOptions = {
4545
) => void,
4646
onRecoverableError?: (
4747
error: mixed,
48-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
48+
errorInfo: {+componentStack?: ?string},
4949
) => void,
5050
};
5151

@@ -71,7 +71,7 @@ export type HydrateRootOptions = {
7171
) => void,
7272
onRecoverableError?: (
7373
error: mixed,
74-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
74+
errorInfo: {+componentStack?: ?string},
7575
) => void,
7676
formState?: ReactFormState<any, any> | null,
7777
};

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,9 @@ function updateDehydratedSuspenseComponent(
27352735
// get an update and we'll never be able to hydrate the final content. Let's just try the
27362736
// client side render instead.
27372737
let digest: ?string;
2738-
let message, stack, componentStack;
2738+
let message;
2739+
let stack = null;
2740+
let componentStack = null;
27392741
if (__DEV__) {
27402742
({digest, message, stack, componentStack} =
27412743
getSuspenseInstanceFallbackErrorDetails(suspenseInstance));
@@ -2762,8 +2764,7 @@ function updateDehydratedSuspenseComponent(
27622764
(error: any).digest = digest;
27632765
capturedValue = createCapturedValueFromError(
27642766
error,
2765-
digest,
2766-
componentStack,
2767+
componentStack === undefined ? null : componentStack,
27672768
);
27682769
}
27692770
return retrySuspenseComponentWithoutHydrating(
@@ -2906,6 +2907,7 @@ function updateDehydratedSuspenseComponent(
29062907
'There was an error while hydrating this Suspense boundary. ' +
29072908
'Switched to client rendering.',
29082909
),
2910+
null,
29092911
);
29102912
return retrySuspenseComponentWithoutHydrating(
29112913
current,

packages/react-reconciler/src/ReactFiberErrorLogger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function defaultOnCaughtError(
9494

9595
export function defaultOnRecoverableError(
9696
error: mixed,
97-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
97+
errorInfo: {+componentStack?: ?string},
9898
) {
9999
reportGlobalError(error);
100100
}

packages/react-reconciler/src/ReactFiberReconciler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export function createContainer(
267267
) => void,
268268
onRecoverableError: (
269269
error: mixed,
270-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
270+
errorInfo: {+componentStack?: ?string},
271271
) => void,
272272
transitionCallbacks: null | TransitionTracingCallbacks,
273273
): OpaqueRoot {
@@ -313,7 +313,7 @@ export function createHydrationContainer(
313313
) => void,
314314
onRecoverableError: (
315315
error: mixed,
316-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
316+
errorInfo: {+componentStack?: ?string},
317317
) => void,
318318
transitionCallbacks: null | TransitionTracingCallbacks,
319319
formState: ReactFormState<any, any> | null,

packages/react-reconciler/src/ReactFiberRoot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export function createFiberRoot(
160160
) => void,
161161
onRecoverableError: (
162162
error: mixed,
163-
errorInfo: {+digest?: ?string, +componentStack?: ?string},
163+
errorInfo: {+componentStack?: ?string},
164164
) => void,
165165
transitionCallbacks: null | TransitionTracingCallbacks,
166166
formState: ReactFormState<any, any> | null,

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,37 +3128,21 @@ function commitRootImpl(
31283128
}
31293129

31303130
function makeErrorInfo(componentStack: ?string) {
3131+
const errorInfo = {
3132+
componentStack,
3133+
};
31313134
if (__DEV__) {
3132-
const errorInfo = {
3133-
componentStack,
3134-
};
3135-
return new Proxy(errorInfo, {
3136-
get(target, prop, receiver) {
3137-
if (prop === 'digest') {
3138-
console.error(
3139-
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3140-
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3141-
' of the Error instance itself.',
3142-
);
3143-
}
3144-
return Reflect.get(target, prop, receiver);
3145-
},
3146-
has(target, prop) {
3147-
if (prop === 'digest') {
3148-
console.error(
3149-
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3150-
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3151-
' of the Error instance itself.',
3152-
);
3153-
}
3154-
return Reflect.has(target, prop);
3135+
Object.defineProperty((errorInfo: any), 'digest', {
3136+
get() {
3137+
console.error(
3138+
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
3139+
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
3140+
' of the Error instance itself.',
3141+
);
31553142
},
31563143
});
3157-
} else {
3158-
return {
3159-
componentStack,
3160-
};
31613144
}
3145+
return errorInfo;
31623146
}
31633147

31643148
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)