Skip to content

Commit

Permalink
fix closure escape
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Sep 22, 2022
1 parent 2caef37 commit a2f917d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,7 @@ describe('ReactDOMFizzServer', () => {
{
onRecoverableError(error, errorInfo) {
expect(() => {
expect(error.digest).toBe('a digest');
expect(errorInfo.digest).toBe('a digest');
}).toErrorDev(
'Warning: You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
Expand Down
49 changes: 31 additions & 18 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2596,24 +2596,10 @@ function commitRootImpl(
const onRecoverableError = root.onRecoverableError;
for (let i = 0; i < recoverableErrors.length; i++) {
const recoverableError = recoverableErrors[i];
const componentStack = recoverableError.stack;
const digest = recoverableError.digest;
let errorInfo;
if (__DEV__) {
errorInfo = {
componentStack,
get digest() {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is deprecated and will be removed in a future version of React.' +
' To access the digest of an Error look for this property on the Error instance itself.',
);
return digest;
},
};
} else {
errorInfo = {componentStack, digest};
}
const errorInfo = makeErrorInfo(
recoverableError.digest,
recoverableError.stack,
);
onRecoverableError(recoverableError.value, errorInfo);
}
}
Expand Down Expand Up @@ -2705,6 +2691,33 @@ function commitRootImpl(
return null;
}

function makeErrorInfo(digest: ?string, componentStack: ?string) {
if (__DEV__) {
const errorInfo = {
componentStack,
digest,
};
Object.defineProperty(errorInfo, 'digest', {
configurable: false,
enumerable: true,
get() {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is deprecated and will be removed in a future version of React.' +
' To access the digest of an Error look for this property on the Error instance itself.',
);
return digest;
},
});
return errorInfo;
} else {
return {
digest,
componentStack,
};
}
}

function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {
if (enableCache) {
const pooledCacheLanes = (root.pooledCacheLanes &= remainingLanes);
Expand Down
49 changes: 31 additions & 18 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2596,24 +2596,10 @@ function commitRootImpl(
const onRecoverableError = root.onRecoverableError;
for (let i = 0; i < recoverableErrors.length; i++) {
const recoverableError = recoverableErrors[i];
const componentStack = recoverableError.stack;
const digest = recoverableError.digest;
let errorInfo;
if (__DEV__) {
errorInfo = {
componentStack,
get digest() {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is deprecated and will be removed in a future version of React.' +
' To access the digest of an Error look for this property on the Error instance itself.',
);
return digest;
},
};
} else {
errorInfo = {componentStack, digest};
}
const errorInfo = makeErrorInfo(
recoverableError.digest,
recoverableError.stack,
);
onRecoverableError(recoverableError.value, errorInfo);
}
}
Expand Down Expand Up @@ -2705,6 +2691,33 @@ function commitRootImpl(
return null;
}

function makeErrorInfo(digest: ?string, componentStack: ?string) {
if (__DEV__) {
const errorInfo = {
componentStack,
digest,
};
Object.defineProperty(errorInfo, 'digest', {
configurable: false,
enumerable: true,
get() {
console.error(
'You are accessing "digest" from the errorInfo object passed to onRecoverableError.' +
' This property is deprecated and will be removed in a future version of React.' +
' To access the digest of an Error look for this property on the Error instance itself.',
);
return digest;
},
});
return errorInfo;
} else {
return {
digest,
componentStack,
};
}
}

function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {
if (enableCache) {
const pooledCacheLanes = (root.pooledCacheLanes &= remainingLanes);
Expand Down

0 comments on commit a2f917d

Please sign in to comment.