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: patch angular wrap detection in rrweb #1543

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Nov 19, 2024

follow-up to #1531 which fixed this for dead clicks

patch rrweb to correctly detect angular's change detection

🎉 tested locally by installing patched version in an angular application and seeing it no longer freezes 🎉

also opened upstream PR here rrweb-io/rrweb#1597

Copy link

vercel bot commented Nov 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Nov 19, 2024 5:25pm

@pauldambra pauldambra requested review from daibhin and a team November 19, 2024 15:54
@pauldambra pauldambra added the bump patch Bump patch version when this PR gets merged label Nov 19, 2024
Comment on lines 9 to 16
+const isFunction = (x) => typeof x === 'function';
+const isNativeFunction = () => isFunction(x) && x.toString().includes("[native code]");
+const isAngularZonePatchedFunction = (x) => {
+ if (!isFunction(x)) {
+ return false;
+ }
+ const prototypeKeys = Object.getOwnPropertyNames(x.prototype || {});
+ return prototypeKeys.some((key) => key.indexOf('__zone'));
+}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copies these three functions from posthog-js that are already being used in #1531

Comment on lines 35 to 40
+ let isUntainted = isNativeFunction(candidate);
+ if (key === 'MutationObserver') {
+ isUntainted = isUntainted && !isAngularZonePatchedFunction(candidate);
+ }
+ return isUntainted;
+ }),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when testing mutation observer it has to be native code and not have angular zone prototypes

Copy link

github-actions bot commented Nov 19, 2024

Size Change: +1.04 kB (+0.03%)

Total Size: 3.12 MB

Filename Size Change
dist/all-external-dependencies.js 204 kB +148 B (+0.07%)
dist/array.full.js 357 kB +148 B (+0.04%)
dist/array.full.no-external.js 356 kB +148 B (+0.04%)
dist/module.full.js 357 kB +148 B (+0.04%)
dist/module.full.no-external.js 356 kB +148 B (+0.04%)
dist/recorder-v2.js 114 kB +148 B (+0.13%)
dist/recorder.js 114 kB +148 B (+0.13%)
ℹ️ View Unchanged
Filename Size
dist/array.full.es5.js 254 kB
dist/array.js 171 kB
dist/array.no-external.js 170 kB
dist/dead-clicks-autocapture.js 13.6 kB
dist/exception-autocapture.js 8.7 kB
dist/external-scripts-loader.js 2.27 kB
dist/main.js 172 kB
dist/module.js 171 kB
dist/module.no-external.js 170 kB
dist/surveys-preview.js 56.7 kB
dist/surveys.js 62.1 kB
dist/tracing-headers.js 1.4 kB
dist/web-vitals.js 10.3 kB

compressed-size-action

@pauldambra pauldambra marked this pull request as draft November 19, 2024 16:40
@pauldambra
Copy link
Member Author

pauldambra commented Nov 19, 2024

frustratingly my test angular application is freezing before this :/

@pauldambra pauldambra force-pushed the fix/patch-angular-wrap-detection-in-rrweb branch from 113a71e to 702929a Compare November 19, 2024 17:22
@pauldambra pauldambra marked this pull request as ready for review November 19, 2024 17:22
@pauldambra pauldambra merged commit 0d5cd52 into main Nov 19, 2024
14 checks passed
@pauldambra pauldambra deleted the fix/patch-angular-wrap-detection-in-rrweb branch November 19, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants