Repository navigation
fix(replay): Keep mutation removals when their node is missing on seek - #370
Open
sentry-junior[bot] wants to merge 1 commit into
Open
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
`applyMutation` reassigned `d.removes` to the removals whose node was in the mirror. Event objects are applied again on every seek, so a removal whose node was only briefly missing was deleted from the event for good, and later playback kept the node in the DOM. Filter into a local `removes` list instead and leave the event untouched. Ported from rrweb-io#2002. Co-Authored-By: George Gritsouk <989898+gggritso@users.noreply.github.com>
Member
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit eaf54f3. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tl;dr we're pulling in an upstream fix that I'm pretty sure will fix a known user bug. The upstream fix isn't merged, but looks reasonable, so I'm feeling optimistic about merging it. Long explanation as follows.
After a seek, such as dragging the timeline back and playing again, the replayer can leave elements on screen that the recorded page had already removed. That shows up as UI elements overlapping each other, even though the user never actually saw that.
applyMutationis called by rrweb during playback, it applies a recorded DOM mutation to the current replay state. A "mutation" has node adds, node removes, attribute changes, etc. Each node has a numeric ID assigned by the recorder, kept track in an object called a "mirror". The replayer keeps track of this mirror, but in some cases mutations are double-applied. If a node was already removed by a first apply, the second apply causes the issue.This is the salient line:
This takes the incoming mutation, and filters the removals in it to only those that have a corresponding node in the relevant DOM. The problem is that if this mutation is double-applied during a seek, it might incorrectly filter out a valid removal and permanently makes that mutation incorrect.
When seeking forward, the situation is fairly simple. Take every incoming mutation, and apply it to the current rendered DOM. When seeking backwards it's harder. We do not have inverses of the mutations, so we can't just play backwards. On every backward seek, we have to find the most recent full snapshot, find all mutations until the current seek point, and apply them all (done using a virtual DOM for performance). Due to a related bug, sometimes during seek, rrweb will double apply a mutation and this creates the problem.
Here's an attempt at an illustrative example.
Imagine that at 3:00, a modal node was added to the page. At 3:05 it was dismissed by the user, and removed. The modal node is removed from the mirror at that point. We start to seek backward from 3:05 to 3:00. As we seek backwards on every seek event rrweb finds the most recent full snapshot, and starts applying relevant mutations to it until it gets to the current seek point. At just after 3:05 the modal has been added and removed since the last full snapshot. So, the seek-initiated rebuild adds the modal and then removes it (very quickly, it's not visible). When the modal is removed, it's removed from the mirror.
If there's a double-apply at the next backwards seek step, it attempts to remove the modal again. The modal is already removed, so that removal is filtered out of the removals list. Now, we keep seeking backwards to an earlier point, when the modal is still open. Now, when we play forward, by the time we get to the mutation that originally removed the modal node, there's no more removal of the modal in it, and the modal stays on the page.
The fix is to not mutate the mutation. Instead, just iterate the removals as normal, and skip anything that doesn't have a corresponding node. It would also be nice to fix the double apply (caused by incorrect handling of custom events) but that's harder and less confident until someone upstream takes a closer look.
This PR is a port of the open upstream fix rrweb-io/rrweb#2002 written by @noatudor which is currently unmerged, but looks reasonable.
Fixes getsentry/sentry#130768
Closes getsentry/sentry#130768
via @gggritso.
--
View Session [Sentry]