@samitouri / QOS-React-1 / commits / df95577db0

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.

Sebastian Markbåge committed Mar 30, 2024 at 18:32 UTC df95577db0d1d7ca383f281bc1d9e6ba5579bef2
8 files changed +25 -43
packages/react-dom/src/client/ReactDOMRoot.js
+2 -2
@@ -45,7 +45,7 @@ export type CreateRootOptions = {
45 ) => void,
46 onRecoverableError?: (
47 error: mixed,
48 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
48 + errorInfo: {+componentStack?: ?string},
49 ) => void,
50 };
51
@@ -71,7 +71,7 @@ export type HydrateRootOptions = {
71 ) => void,
72 onRecoverableError?: (
73 error: mixed,
74 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
74 + errorInfo: {+componentStack?: ?string},
75 ) => void,
76 formState?: ReactFormState<any, any> | null,
77 };
packages/react-reconciler/src/ReactCapturedValue.js
+2 -6
@@ -17,7 +17,6 @@ export type CapturedValue<T> = {
17 +value: T,
18 source: Fiber | null,
19 stack: string | null,
20 - digest: string | null,
20 };
21
22 export function createCapturedValueAtFiber<T>(
@@ -43,14 +42,12 @@ export function createCapturedValueAtFiber<T>(
42 value,
43 source,
44 stack,
46 - digest: null,
45 };
46 }
47
48 export function createCapturedValueFromError(
49 value: Error,
52 - digest: ?string,
53 - stack: ?string,
50 + stack: null | string,
51 ): CapturedValue<Error> {
52 if (typeof stack === 'string') {
53 CapturedStacks.set(value, stack);
@@ -58,7 +55,6 @@ export function createCapturedValueFromError(
55 return {
56 value,
57 source: null,
61 - stack: stack != null ? stack : null,
62 - digest: digest != null ? digest : null,
58 + stack: stack,
59 };
60 }
packages/react-reconciler/src/ReactFiberBeginWork.js
+5 -3
@@ -2735,7 +2735,9 @@ function updateDehydratedSuspenseComponent(
2735 // get an update and we'll never be able to hydrate the final content. Let's just try the
2736 // client side render instead.
2737 let digest: ?string;
2738 - let message, stack, componentStack;
2738 + let message;
2739 + let stack = null;
2740 + let componentStack = null;
2741 if (__DEV__) {
2742 ({digest, message, stack, componentStack} =
2743 getSuspenseInstanceFallbackErrorDetails(suspenseInstance));
@@ -2762,8 +2764,7 @@ function updateDehydratedSuspenseComponent(
2764 (error: any).digest = digest;
2765 capturedValue = createCapturedValueFromError(
2766 error,
2765 - digest,
2766 - componentStack,
2767 + componentStack === undefined ? null : componentStack,
2768 );
2769 }
2770 return retrySuspenseComponentWithoutHydrating(
@@ -2906,6 +2907,7 @@ function updateDehydratedSuspenseComponent(
2907 'There was an error while hydrating this Suspense boundary. ' +
2908 'Switched to client rendering.',
2909 ),
2910 + null,
2911 );
2912 return retrySuspenseComponentWithoutHydrating(
2913 current,
packages/react-reconciler/src/ReactFiberErrorLogger.js
+1 -1
@@ -94,7 +94,7 @@ export function defaultOnCaughtError(
94
95 export function defaultOnRecoverableError(
96 error: mixed,
97 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
97 + errorInfo: {+componentStack?: ?string},
98 ) {
99 reportGlobalError(error);
100 }
packages/react-reconciler/src/ReactFiberReconciler.js
+2 -2
@@ -267,7 +267,7 @@ export function createContainer(
267 ) => void,
268 onRecoverableError: (
269 error: mixed,
270 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
270 + errorInfo: {+componentStack?: ?string},
271 ) => void,
272 transitionCallbacks: null | TransitionTracingCallbacks,
273 ): OpaqueRoot {
@@ -313,7 +313,7 @@ export function createHydrationContainer(
313 ) => void,
314 onRecoverableError: (
315 error: mixed,
316 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
316 + errorInfo: {+componentStack?: ?string},
317 ) => void,
318 transitionCallbacks: null | TransitionTracingCallbacks,
319 formState: ReactFormState<any, any> | null,
packages/react-reconciler/src/ReactFiberRoot.js
+1 -1
@@ -160,7 +160,7 @@ export function createFiberRoot(
160 ) => void,
161 onRecoverableError: (
162 error: mixed,
163 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
163 + errorInfo: {+componentStack?: ?string},
164 ) => void,
165 transitionCallbacks: null | TransitionTracingCallbacks,
166 formState: ReactFormState<any, any> | null,
packages/react-reconciler/src/ReactFiberWorkLoop.js
+11 -27
@@ -3128,37 +3128,21 @@ function commitRootImpl(
3128 }
3129
3130 function makeErrorInfo(componentStack: ?string) {
3131 + const errorInfo = {
3132 + componentStack,
3133 + };
3134 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 + );
3142 },
3143 });
3157 - } else {
3158 - return {
3159 - componentStack,
3160 - };
3144 }
3145 + return errorInfo;
3146 }
3147
3148 function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {
packages/react-reconciler/src/ReactInternalTypes.js
+1 -1
@@ -273,7 +273,7 @@ type BaseFiberRootProperties = {
273 ) => void,
274 onRecoverableError: (
275 error: mixed,
276 - errorInfo: {+digest?: ?string, +componentStack?: ?string},
276 + errorInfo: {+componentStack?: ?string},
277 ) => void,
278
279 formState: ReactFormState<any, any> | null,