Skip to content

fix(replay): Keep mutation removals when their node is missing on seek - #370

Open
sentry-junior[bot] wants to merge 1 commit into
sentry-v2from
fix/replay-keep-mutation-removes
Open

sentry-junior[bot] wants to merge 1 commit into
sentry-v2from
fix/replay-keep-mutation-removes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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.

applyMutation is 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:

d.removes = d.removes.filter(

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]

`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>

Copy link
Copy Markdown
Member

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ 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.

@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

REPLAY-1045

@gggritso
gggritso requested a review from logaretm November 27, 2026 21:11
@gggritso
gggritso marked this pull request as ready for review November 27, 2026 21:11
@sentry-junior
sentry-junior Bot requested a review from gggritso November 27, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replay shows stale overlapping modals after seeking backward

1 participant