Skip to content

Commit f8377ff

Browse files
committed
feat(core)!: Remove memoBuilder export & WeakSet fallback
All envs targeted for v9 should support WeakSet.
1 parent 9030f37 commit f8377ff

File tree

4 files changed

+28
-58
lines changed

4 files changed

+28
-58
lines changed

docs/migration/v8-to-v9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Sentry.init({
132132
- The `urlEncode` method has been removed. There is no replacement.
133133
- The `getDomElement` method has been removed. There is no replacement.
134134
- The `Request` type has been removed. Use `RequestEventData` type instead.
135+
- The `memoBuilder` method has been removed. There is no replacement.
135136

136137
### `@sentry/browser`
137138

packages/core/src/utils-hoist/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export {
3838
} from './is';
3939
export { isBrowser } from './isBrowser';
4040
export { CONSOLE_LEVELS, consoleSandbox, logger, originalConsoleMethods } from './logger';
41-
// eslint-disable-next-line deprecation/deprecation
42-
export { memoBuilder } from './memo';
4341
export {
4442
addContextToFrame,
4543
addExceptionMechanism,

packages/core/src/utils-hoist/memo.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/core/src/utils-hoist/normalize.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { Primitive } from '../types-hoist';
22

33
import { isSyntheticEvent, isVueViewModel } from './is';
4-
import type { MemoFunc } from './memo';
5-
import { memoBuilder } from './memo';
64
import { convertToPlainObject } from './object';
75
import { getFunctionName } from './stacktrace';
86

@@ -13,6 +11,13 @@ type Prototype = { constructor: (...args: unknown[]) => unknown };
1311
// might be arrays.
1412
type ObjOrArray<T> = { [key: string]: T };
1513

14+
type MemoFunc = [
15+
// memoize
16+
(obj: object) => boolean,
17+
// unmemoize
18+
(obj: object) => void,
19+
];
20+
1621
/**
1722
* Recursively normalizes the given object.
1823
*
@@ -74,8 +79,7 @@ function visit(
7479
value: unknown,
7580
depth: number = +Infinity,
7681
maxProperties: number = +Infinity,
77-
// eslint-disable-next-line deprecation/deprecation
78-
memo: MemoFunc = memoBuilder(),
82+
memo = memoBuilder(),
7983
): Primitive | ObjOrArray<unknown> {
8084
const [memoize, unmemoize] = memo;
8185

@@ -304,3 +308,22 @@ export function normalizeUrlToBase(url: string, basePath: string): string {
304308
.replace(new RegExp(`(file://)?/*${escapedBase}/*`, 'ig'), 'app:///')
305309
);
306310
}
311+
312+
/**
313+
* Helper to decycle json objects
314+
*/
315+
function memoBuilder(): MemoFunc {
316+
const inner = new WeakSet<object>();
317+
function memoize(obj: object): boolean {
318+
if (inner.has(obj)) {
319+
return true;
320+
}
321+
inner.add(obj);
322+
return false;
323+
}
324+
325+
function unmemoize(obj: object): void {
326+
inner.delete(obj);
327+
}
328+
return [memoize, unmemoize];
329+
}

0 commit comments

Comments
 (0)