8000 fix: Preserve original user data for explicitly updated scopes (#2991) · TGTGamer/sentry-javascript@1c72bf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c72bf9

Browse files
authored
fix: Preserve original user data for explicitly updated scopes (getsentry#2991)
1 parent d03b406 commit 1c72bf9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/hub/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class Scope implements ScopeInterface {
287287
this._tags = { ...this._tags, ...captureContext._tags };
288288
this._extra = { ...this._extra, ...captureContext._extra };
289289
this._contexts = { ...this._contexts, ...captureContext._contexts };
290-
if (captureContext._user) {
290+
if (captureContext._user && Object.keys(captureContext._user).length) {
291291
this._user = captureContext._user;
292292
}
293293
if (captureContext._level) {

packages/hub/test/scope.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,26 @@ describe('Scope', () => {
399399
expect(updatedScope._fingerprint).toEqual(['bar']);
400400
});
401401

402+
test('given an empty instance of Scope, it should preserve all the original scope data', () => {
403+
const updatedScope = scope.update(new Scope()) as any;
404+
405+
expect(updatedScope._tags).toEqual({
406+
bar: '2',
407+
foo: '1',
408+
});
409+
expect(updatedScope._extra).toEqual({
410+
bar: '2',
411+
foo: '1',
412+
});
413+
expect(updatedScope._contexts).toEqual({
414+
bar: { id: '2' },
415+
foo: { id: '1' },
416+
});
417+
expect(updatedScope._user).toEqual({ id: '1337' });
418+
expect(updatedScope._level).toEqual(Severity.Info);
419+
expect(updatedScope._fingerprint).toEqual(['foo']);
420+
});
421+
402422
test('given a plain object, it should merge two together, with the passed object having priority', () => {
403423
const localAttributes = {
404424
contexts: { bar: { id: '3' }, baz: { id: '4' } },

0 commit comments

Comments
 (0)
0