fix: angular wrapped mutationobserver detection (#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>
This commit is contained in:
Paul D'Ambra
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 464554039d
commit 97c93a171d
2 changed files with 23 additions and 1 deletions

View File

@@ -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] {
@@ -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];
}