Skip to content

Commit 82cebd3

Browse files
authored
ref: Fix comment for normalize (#7954)
1 parent 6de02c0 commit 82cebd3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

packages/utils/src/normalize.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ function visit(
100100
return value as ObjOrArray<unknown>;
101101
}
102102

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;
111110

112111
// We're also done if we've reached the max depth
113-
if (overriddenDepth === 0) {
112+
if (remainingDepth === 0) {
114113
// At this point we know `serialized` is a string of the form `"[object XXXX]"`. Clean it up so it's just `"[XXXX]"`.
115114
return stringified.replace('object ', '');
116115
}
@@ -126,7 +125,7 @@ function visit(
126125
try {
127126
const jsonValue = valueWithToJSON.toJSON();
128127
// 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);
130129
} catch (err) {
131130
// pass (The built-in `toJSON` failed, but we can still try to do it ourselves)
132131
}
@@ -155,7 +154,7 @@ function visit(
155154

156155
// Recursively visit all the child nodes
157156
const visitValue = visitable[visitKey];
158-
normalized[visitKey] = visit(visitKey, visitValue, overriddenDepth - 1, maxProperties, memo);
157+
normalized[visitKey] = visit(visitKey, visitValue, remainingDepth - 1, maxProperties, memo);
159158

160159
numAdded++;
161160
}

0 commit comments

Comments
 (0)