Skip to content

Commit 40d5bee

Browse files
committed
only stash if extensible
1 parent 93543f3 commit 40d5bee

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/react-reconciler/src/ReactCapturedValue.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ export function createCapturedValueAtFiber<T>(
2323
value: T,
2424
source: Fiber,
2525
): CapturedValue<T> {
26+
// If the value is an error, call this function immediately after it is thrown
27+
// so the stack is accurate.
2628
let stack;
27-
if (value && typeof value === 'object') {
28-
if (hasOwnProperty.call(value, '_componentStack')) {
29-
stack = (value._componentStack: any);
30-
} else {
31-
stack = (value: any)._componentStack = getStackByFiberInDevAndProd(
32-
source,
33-
);
34-
}
29+
if (value != null && hasOwnProperty.call(value, '_componentStack')) {
30+
// Read the stack from the value if it was set by an earlier capture
31+
stack = (value: any)._componentStack;
32+
} else if (Object.isExtensible((value: any))) {
33+
// If the value is an extensible type, stash the stack on the value. We
34+
// check extensibility for the edge case where one throws a frozen object or
35+
// something inherently non-extensible like null or a string
36+
stack = (value: any)._componentStack = getStackByFiberInDevAndProd(source);
3537
} else {
38+
// We can't stash the stack on the value
3639
stack = getStackByFiberInDevAndProd(source);
3740
}
38-
// If the value is an error, call this function immediately after it is thrown
39-
// so the stack is accurate.
41+
4042
return {
4143
value,
4244
source,

0 commit comments

Comments
 (0)