File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
packages/react-reconciler/src Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -23,20 +23,22 @@ export function createCapturedValueAtFiber<T>(
23
23
value : T ,
24
24
source : Fiber ,
25
25
) : CapturedValue < T > {
26
+ // If the value is an error, call this function immediately after it is thrown
27
+ // so the stack is accurate.
26
28
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 ) ;
35
37
} else {
38
+ // We can't stash the stack on the value
36
39
stack = getStackByFiberInDevAndProd ( source ) ;
37
40
}
38
- // If the value is an error, call this function immediately after it is thrown
39
- // so the stack is accurate.
41
+
40
42
return {
41
43
value ,
42
44
source,
You can’t perform that action at this time.
0 commit comments