Skip to content

feat(core)!: Remove memoBuilder export & WeakSet fallback #14859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migration/v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Sentry.init({
- The `urlEncode` method has been removed. There is no replacement.
- The `getDomElement` method has been removed. There is no replacement.
- The `Request` type has been removed. Use `RequestEventData` type instead.
- The `memoBuilder` method has been removed. There is no replacement.

### `@sentry/browser`

Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/utils-hoist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export {
} from './is';
export { isBrowser } from './isBrowser';
export { CONSOLE_LEVELS, consoleSandbox, logger, originalConsoleMethods } from './logger';
// eslint-disable-next-line deprecation/deprecation
export { memoBuilder } from './memo';
export {
addContextToFrame,
addExceptionMechanism,
Expand Down
52 changes: 0 additions & 52 deletions packages/core/src/utils-hoist/memo.ts

This file was deleted.

31 changes: 27 additions & 4 deletions packages/core/src/utils-hoist/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Primitive } from '../types-hoist';

import { isSyntheticEvent, isVueViewModel } from './is';
import type { MemoFunc } from './memo';
import { memoBuilder } from './memo';
import { convertToPlainObject } from './object';
import { getFunctionName } from './stacktrace';

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

type MemoFunc = [
// memoize
(obj: object) => boolean,
// unmemoize
(obj: object) => void,
];

/**
* Recursively normalizes the given object.
*
Expand Down Expand Up @@ -74,8 +79,7 @@ function visit(
value: unknown,
depth: number = +Infinity,
maxProperties: number = +Infinity,
// eslint-disable-next-line deprecation/deprecation
memo: MemoFunc = memoBuilder(),
memo = memoBuilder(),
): Primitive | ObjOrArray<unknown> {
const [memoize, unmemoize] = memo;

Expand Down Expand Up @@ -304,3 +308,22 @@ export function normalizeUrlToBase(url: string, basePath: string): string {
.replace(new RegExp(`(file://)?/*${escapedBase}/*`, 'ig'), 'app:///')
);
}

/**
* Helper to decycle json objects
*/
function memoBuilder(): MemoFunc {
const inner = new WeakSet<object>();
function memoize(obj: object): boolean {
if (inner.has(obj)) {
return true;
}
inner.add(obj);
return false;
}

function unmemoize(obj: object): void {
inner.delete(obj);
}
return [memoize, unmemoize];
}
Loading