Skip to content

Commit ce9b196

Browse files
committed
fix(replay): don't write the data-sentry-component fallback back onto the mirror
`getAttributesToRecord` is handed rrweb's serialized attributes, which are shared with events that may not be serialized yet, and it was writing the `data-sentry-element` -> `data-sentry-component` fallback back onto them. Derive it on the returned object instead.
1 parent 56af2d4 commit ce9b196

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/replay-internal/src/coreHandlers/util/getAttributesToRecord.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export const BREADCRUMB_RELEVANT_ATTRIBUTES = new Set([...ATTRIBUTES_TO_RECORD,
2727
*/
2828
export function getAttributesToRecord(attributes: Record<string, unknown>): Record<string, unknown> {
2929
const obj: Record<string, unknown> = {};
30-
if (!attributes['data-sentry-component'] && attributes['data-sentry-element']) {
31-
attributes['data-sentry-component'] = attributes['data-sentry-element'];
32-
}
30+
3331
for (const key in attributes) {
3432
if (ATTRIBUTES_TO_RECORD.has(key)) {
3533
let normalizedKey = key;
@@ -42,5 +40,11 @@ export function getAttributesToRecord(attributes: Record<string, unknown>): Reco
4240
}
4341
}
4442

43+
// `attributes` is the serialized node held by rrweb's mirror, which is the same object that was
44+
// emitted in an earlier `adds` payload, so this fallback must not be written back onto it.
45+
if (!obj['data-sentry-component'] && attributes['data-sentry-element']) {
46+
obj['data-sentry-component'] = attributes['data-sentry-element'];
47+
}
48+
4549
return obj;
4650
}

packages/replay-internal/test/unit/coreHandlers/util/getAttributesToRecord.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ it('records data-sentry-element as data-sentry-component when appropriate', func
4949
['data-sentry-component']: 'element',
5050
});
5151
});
52+
53+
it('does not write the data-sentry-component fallback back onto the passed attributes', function () {
54+
// These are rrweb's serialized attributes, shared with events that may not be serialized yet.
55+
const attributes = { ['data-sentry-element']: 'element' };
56+
57+
getAttributesToRecord(attributes);
58+
59+
expect(attributes).toEqual({ ['data-sentry-element']: 'element' });
60+
});

0 commit comments

Comments
 (0)