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: more robust rootShadowHost check #50

Merged
merged 1 commit into from
Feb 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default class MutationBuffer {
// ensure shadowHost is a Node, or doc.contains will throw an error
const notInDoc =
!this.doc.contains(n) &&
(rootShadowHost === null || !this.doc.contains(rootShadowHost));
(!rootShadowHost || !this.doc.contains(rootShadowHost));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm would you mind explaining how this fixes the reported issue?
Not sure what I'm missing here but I tried reproducing this locally, by explicitly calling this.doc.contains(undefined) but the call seemed to return false and didn't crash.

Also, any chance that this is caused by the line above (n)?

Copy link
Member

Choose a reason for hiding this comment

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

Ofc chances are that in my simple test app, doc is handling the contains call somewhat differently than in Sentry...

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, oof, I thought that contains(undefined) would break it. If that works, then this isn't a fix at all, then it obv. is a different issue. Then I guess we'd need to do a rootShadowHost instanceof Node check or something along these lines 🤔

if (!n.parentNode || notInDoc) {
return;
}
Expand Down