Skip to content

Commit

Permalink
Finish cleaning up digest from onRecoverableError (facebook#28686)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage committed Mar 30, 2024
1 parent 9f835e6 commit df95577
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 43 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom/src/client/ReactDOMRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type CreateRootOptions = {
) => void,
onRecoverableError?: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,
};

Expand All @@ -71,7 +71,7 @@ export type HydrateRootOptions = {
) => void,
onRecoverableError?: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,
formState?: ReactFormState<any, any> | null,
};
Expand Down
8 changes: 2 additions & 6 deletions packages/react-reconciler/src/ReactCapturedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export type CapturedValue<T> = {
+value: T,
source: Fiber | null,
stack: string | null,
digest: string | null,
};

export function createCapturedValueAtFiber<T>(
Expand All @@ -43,22 +42,19 @@ export function createCapturedValueAtFiber<T>(
value,
source,
stack,
digest: null,
};
}

export function createCapturedValueFromError(
value: Error,
digest: ?string,
stack: ?string,
stack: null | string,
): CapturedValue<Error> {
if (typeof stack === 'string') {
CapturedStacks.set(value, stack);
}
return {
value,
source: null,
stack: stack != null ? stack : null,
digest: digest != null ? digest : null,
stack: stack,
};
}
8 changes: 5 additions & 3 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2735,7 +2735,9 @@ function updateDehydratedSuspenseComponent(
// get an update and we'll never be able to hydrate the final content. Let's just try the
// client side render instead.
let digest: ?string;
let message, stack, componentStack;
let message;
let stack = null;
let componentStack = null;
if (__DEV__) {
({digest, message, stack, componentStack} =
getSuspenseInstanceFallbackErrorDetails(suspenseInstance));
Expand All @@ -2762,8 +2764,7 @@ function updateDehydratedSuspenseComponent(
(error: any).digest = digest;
capturedValue = createCapturedValueFromError(
error,
digest,
componentStack,
componentStack === undefined ? null : componentStack,
);
}
return retrySuspenseComponentWithoutHydrating(
Expand Down Expand Up @@ -2906,6 +2907,7 @@ function updateDehydratedSuspenseComponent(
'There was an error while hydrating this Suspense boundary. ' +
'Switched to client rendering.',
),
null,
);
return retrySuspenseComponentWithoutHydrating(
current,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberErrorLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function defaultOnCaughtError(

export function defaultOnRecoverableError(
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) {
reportGlobalError(error);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function createContainer(
) => void,
onRecoverableError: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,
transitionCallbacks: null | TransitionTracingCallbacks,
): OpaqueRoot {
Expand Down Expand Up @@ -313,7 +313,7 @@ export function createHydrationContainer(
) => void,
onRecoverableError: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,
transitionCallbacks: null | TransitionTracingCallbacks,
formState: ReactFormState<any, any> | null,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function createFiberRoot(
) => void,
onRecoverableError: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,
transitionCallbacks: null | TransitionTracingCallbacks,
formState: ReactFormState<any, any> | null,
Expand Down
38 changes: 11 additions & 27 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3128,37 +3128,21 @@ function commitRootImpl(
}

function makeErrorInfo(componentStack: ?string) {
const errorInfo = {
componentStack,
};
if (__DEV__) {
const errorInfo = {
componentStack,
};
return new Proxy(errorInfo, {
get(target, prop, receiver) {
if (prop === 'digest') {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
' of the Error instance itself.',
);
}
return Reflect.get(target, prop, receiver);
},
has(target, prop) {
if (prop === 'digest') {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
' of the Error instance itself.',
);
}
return Reflect.has(target, prop);
Object.defineProperty((errorInfo: any), 'digest', {
get() {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is no longer provided as part of errorInfo but can be accessed as a property' +
' of the Error instance itself.',
);
},
});
} else {
return {
componentStack,
};
}
return errorInfo;
}

function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ type BaseFiberRootProperties = {
) => void,
onRecoverableError: (
error: mixed,
errorInfo: {+digest?: ?string, +componentStack?: ?string},
errorInfo: {+componentStack?: ?string},
) => void,

formState: ReactFormState<any, any> | null,
Expand Down

0 comments on commit df95577

Please sign in to comment.