Skip to content
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

fix: angular wrapped mutationobserver detection #1597

Merged
merged 7 commits into from
Dec 6, 2024
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
5 changes: 5 additions & 0 deletions .changeset/moody-experts-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rrweb/record": patch
---

Correctly detect when angular has wrapped mutation observer
19 changes: 18 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ const testableMethods = {

const untaintedBasePrototype: Partial<BasePrototypeCache> = {};

/*
When angular patches things - particularly the MutationObserver -
they pass the `isNativeFunction` check
That then causes performance issues
because Angular's change detection
doesn't like sharing a mutation observer
Checking for the presence of the Zone object
on global is a good-enough proxy for Angular
to cover most cases
(you can configure zone.js to have a different name
on the global object and should then manually run rrweb
outside the Zone)
*/
export const isAngularZonePresent = (): boolean => {
return !!(globalThis as { Zone?: unknown }).Zone;
};

export function getUntaintedPrototype<T extends keyof BasePrototypeCache>(
key: T,
): BasePrototypeCache[T] {
Expand Down Expand Up @@ -63,7 +80,7 @@ export function getUntaintedPrototype<T extends keyof BasePrototypeCache>(
),
);

if (isUntaintedAccessors && isUntaintedMethods) {
if (isUntaintedAccessors && isUntaintedMethods && !isAngularZonePresent()) {
untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];
return defaultObj.prototype as BasePrototypeCache[T];
}
Expand Down
Loading