Skip to content

Commit 2188e1a

Browse files
committed
flat drop only
1 parent f2cbba1 commit 2188e1a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

packages/browser/src/sdk.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { Client, DsnLike, Integration, Options } from '@sentry/core';
12
import {
23
consoleSandbox,
34
dedupeIntegration,
4-
dropUndefinedKeys,
55
functionToStringIntegration,
66
getCurrentScope,
77
getIntegrationsToSetup,
@@ -13,7 +13,6 @@ import {
1313
stackParserFromStackParserOptions,
1414
supportsFetch,
1515
} from '@sentry/core';
16-
import type { Client, DsnLike, Integration, Options } from '@sentry/core';
1716
import type { BrowserClientOptions, BrowserOptions } from './client';
1817
import { BrowserClient } from './client';
1918
import { DEBUG_BUILD } from './debug-build';
@@ -67,10 +66,27 @@ function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOptions {
6766

6867
return {
6968
...defaultOptions,
70-
...dropUndefinedKeys(optionsArg),
69+
...dropUndefinedKeysFlat(optionsArg),
7170
};
7271
}
7372

73+
/**
74+
* In contrast to the regular `dropUndefinedKeys` method,
75+
* this one does not deep-drop keys, but only on the top level.
76+
*/
77+
function dropUndefinedKeysFlat<T extends object>(obj: T): Partial<T> {
78+
const mutatetedObj: Partial<T> = {};
79+
80+
for (const k of Object.getOwnPropertyNames(obj)) {
81+
const key = k as keyof T;
82+
if (obj[key] !== undefined) {
83+
mutatetedObj[key] = obj[key];
84+
}
85+
}
86+
87+
return mutatetedObj;
88+
}
89+
7490
type ExtensionProperties = {
7591
chrome?: Runtime;
7692
browser?: Runtime;

0 commit comments

Comments
 (0)