Skip to content

Commit

Permalink
Finish cleaning up digest from onRecoverableError
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 cc56bed commit 2f8838f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 42 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,
};
}
9 changes: 7 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,8 @@ 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;
let message;
let stack = null;
if (__DEV__) {
({digest, message, stack} =
getSuspenseInstanceFallbackErrorDetails(suspenseInstance));
Expand All @@ -2670,7 +2671,10 @@ function updateDehydratedSuspenseComponent(
);
}
(error: any).digest = digest;
capturedValue = createCapturedValueFromError(error, digest, stack);
capturedValue = createCapturedValueFromError(
error,
stack === undefined ? null : stack,
);
}
return retrySuspenseComponentWithoutHydrating(
current,
Expand Down Expand Up @@ -2812,6 +2816,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 @@ -3121,37 +3121,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 2f8838f

Please sign in to comment.