-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix (rrdom): Fix edge case where oldChild can become detach causing the recursive function to end early #1718
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
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 4f74fe6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/rrdom/src/diff.ts
Outdated
const newNode = createOrGetNode(newChild, replayer.mirror, rrnodeMirror); | ||
|
||
try { | ||
handleInsertBefore(oldTree, newNode, oldChild); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be a silly question... where is handleInsertBefore
defined?
i don't find it in rrweb at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, maybe this PR is incomplete? @arivyiii is that a mispelling or something that was left out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed your messages. This PR was originally using handleInsertBefore (a safe wrapper around oldTree.insertBefore from another commit), but since oldTree.insertBefore works fine for this use case, I've updated the PR accordingly.
…function to end early
f428458
to
4f74fe6
Compare
Your test case is very helpful. |
Yeah, it was a strange case that occurred in a few of our replays when users were using this extension: https://chromewebstore.google.com/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbieeh?hl=en-US. For some reason, the style tags were being appended with the same node ID back to back. I wasn’t able to reproduce it on any site with the recorder, but while debugging the replay I noticed that the childNode had a nextSibling, which was lost once it returned to diffChildren. We felt it was a safe enough change since for most replays they will never enter this block of code and if this edge case occur it would get resolved versus our users having to deal with a distorted replay. |
Fix an edge case in diffChildren: when we replace an old child via oldTree.parentNode?.replaceChild(calibratedOldTree, oldTree); its nextSibling pointer is lost, causing the diff loop to exit early and inadvertently remove subsequent elements and styles.