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:
5
.changeset/moody-experts-build.md
Normal file
5
.changeset/moody-experts-build.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@rrweb/record": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Correctly detect when angular has wrapped mutation observer
|
||||||
@@ -28,6 +28,23 @@ const testableMethods = {
|
|||||||
|
|
||||||
const untaintedBasePrototype: Partial<BasePrototypeCache> = {};
|
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>(
|
export function getUntaintedPrototype<T extends keyof BasePrototypeCache>(
|
||||||
key: T,
|
key: T,
|
||||||
): BasePrototypeCache[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];
|
untaintedBasePrototype[key] = defaultObj.prototype as BasePrototypeCache[T];
|
||||||
return defaultObj.prototype as BasePrototypeCache[T];
|
return defaultObj.prototype as BasePrototypeCache[T];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user