Skip to content

Commit 18fcf74

Browse files
pauldambraJuice10
authored andcommitted
fix: angular wrapped mutationobserver detection (rrweb-io#1597)
* fix: angular wrapped mutationobserver detection * add change set * fix * prettier * following posthog prod * manually prettier * Update .changeset/moody-experts-build.md Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com> --------- Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>
1 parent b5f83f7 commit 18fcf74

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.changeset/moody-experts-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rrweb/record": patch
3+
---
4+
5+
Correctly detect when angular has wrapped mutation observer

packages/utils/src/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ const testableMethods = {
2828

2929
const untaintedBasePrototype: Partial<BasePrototypeCache> = {};
3030

31+
/*
32+
When angular patches things - particularly the MutationObserver -
33+
they pass the `isNativeFunction` check
34+
That then causes performance issues
35+
because Angular's change detection
36+
doesn't like sharing a mutation observer
37+
Checking for the presence of the Zone object
38+
on global is a good-enough proxy for Angular
39+
to cover most cases
40+
(you can configure zone.js to have a different name
41+
on the global object and should then manually run rrweb
42+
outside the Zone)
43+
*/
44+
export const isAngularZonePresent = (): boolean => {
45+
return !!(globalThis as { Zone?: unknown }).Zone;
46+
};
47+
3148
export function getUntaintedPrototype<T extends keyof BasePrototypeCache>(
3249
key: T,
3350
): BasePrototypeCache[T] {
@@ -63,7 +80,7 @@ export function getUntaintedPrototype<T extends keyof BasePrototypeCache>(
6380
),
6481
);
6582

66-
if (isUntaintedAccessors && isUntaintedMethods) {
83+
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
6784
untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];
6885
return defaultObj.prototype as BasePrototypeCache[T];
6986
}

0 commit comments

Comments
 (0)