Skip to content

Commit

Permalink
only stash if extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Dec 3, 2022
1 parent 93543f3 commit 40d5bee
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/react-reconciler/src/ReactCapturedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ export function createCapturedValueAtFiber<T>(
value: T,
source: Fiber,
): CapturedValue<T> {
// If the value is an error, call this function immediately after it is thrown
// so the stack is accurate.
let stack;
if (value && typeof value === 'object') {
if (hasOwnProperty.call(value, '_componentStack')) {
stack = (value._componentStack: any);
} else {
stack = (value: any)._componentStack = getStackByFiberInDevAndProd(
source,
);
}
if (value != null && hasOwnProperty.call(value, '_componentStack')) {
// Read the stack from the value if it was set by an earlier capture
stack = (value: any)._componentStack;
} else if (Object.isExtensible((value: any))) {
// If the value is an extensible type, stash the stack on the value. We
// check extensibility for the edge case where one throws a frozen object or
// something inherently non-extensible like null or a string
stack = (value: any)._componentStack = getStackByFiberInDevAndProd(source);
} else {
// We can't stash the stack on the value
stack = getStackByFiberInDevAndProd(source);
}
// If the value is an error, call this function immediately after it is thrown
// so the stack is accurate.

return {
value,
source,
Expand Down

0 comments on commit 40d5bee

Please sign in to comment.