@@ -100,17 +100,16 @@ function visit(
100
100
return value as ObjOrArray < unknown > ;
101
101
}
102
102
103
- // Do not normalize objects that we know have already been normalized. As a general rule, the
104
- // "__sentry_skip_normalization__" property should only be used sparingly and only should only be set on objects that
105
- // have already been normalized.
106
- let overriddenDepth = depth ;
107
-
108
- if ( typeof ( value as ObjOrArray < unknown > ) [ '__sentry_override_normalization_depth__' ] === 'number' ) {
109
- overriddenDepth = ( value as ObjOrArray < unknown > ) [ '__sentry_override_normalization_depth__' ] as number ;
110
- }
103
+ // We can set `__sentry_override_normalization_depth__` on an object to ensure that from there
104
+ // We keep a certain amount of depth.
105
+ // This should be used sparingly, e.g. we use it for the redux integration to ensure we get a certain amount of state.
106
+ const remainingDepth =
107
+ typeof ( value as ObjOrArray < unknown > ) [ '__sentry_override_normalization_depth__' ] === 'number'
108
+ ? ( ( value as ObjOrArray < unknown > ) [ '__sentry_override_normalization_depth__' ] as number )
109
+ : depth ;
111
110
112
111
// We're also done if we've reached the max depth
113
- if ( overriddenDepth === 0 ) {
112
+ if ( remainingDepth === 0 ) {
114
113
// At this point we know `serialized` is a string of the form `"[object XXXX]"`. Clean it up so it's just `"[XXXX]"`.
115
114
return stringified . replace ( 'object ' , '' ) ;
116
115
}
@@ -126,7 +125,7 @@ function visit(
126
125
try {
127
126
const jsonValue = valueWithToJSON . toJSON ( ) ;
128
127
// We need to normalize the return value of `.toJSON()` in case it has circular references
129
- return visit ( '' , jsonValue , overriddenDepth - 1 , maxProperties , memo ) ;
128
+ return visit ( '' , jsonValue , remainingDepth - 1 , maxProperties , memo ) ;
130
129
} catch ( err ) {
131
130
// pass (The built-in `toJSON` failed, but we can still try to do it ourselves)
132
131
}
@@ -155,7 +154,7 @@ function visit(
155
154
156
155
// Recursively visit all the child nodes
157
156
const visitValue = visitable [ visitKey ] ;
158
- normalized [ visitKey ] = visit ( visitKey , visitValue , overriddenDepth - 1 , maxProperties , memo ) ;
157
+ normalized [ visitKey ] = visit ( visitKey , visitValue , remainingDepth - 1 , maxProperties , memo ) ;
159
158
160
159
numAdded ++ ;
161
160
}
0 commit comments