Skip to content

feat(rrweb): Allow onMutation to return a filtered list of mutations - #341

Merged
mydea merged 1 commit into
sentry-v2from
feat/on-mutation-filter
Oct 27, 2026
Merged

mydea merged 1 commit into
sentry-v2from
feat/on-mutation-filter

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 23, 2026

Copy link
Copy Markdown

onMutation can currently only accept or drop a whole mutation batch. The Replay SDK needs per-mutation control for two cases:

This PR adds two things:

  • onMutation may return a MutationRecord[]. rrweb then processes only that subset. Returning false still skips the batch. Returning true or nothing still processes everything.
  • onMutation gets a second helpers argument with isBlocked(node). It uses the recorder's own blockClass/blockSelector/unblockSelector rules, checking ancestors too, so callers don't have to re-implement them.

Overhead is kept to a minimum. The helpers object is created once per observer, not per batch. isBlocked only runs when the caller invokes it, so the SDK can limit it to batches that exceed the mutation limit. The only new per-batch work is one Array.isArray check. This also drops the per-batch .bind() on processMutations, which is already an arrow-function property. Existing callers that return booleans behave the same.

via Francesco Gringl-Novy.

--

View Junior Session [Sentry]

onMutation can now return an array of MutationRecords to only process
that subset, in addition to returning false to skip the whole batch.
It also receives an isBlocked helper that applies the recorder's block
rules, so callers can e.g. exclude blocked mutations from their own
mutation limits without re-implementing block logic.

Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
@mydea
mydea marked this pull request as ready for review October 23, 2026 07:43

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a case where replay desyncs with the dom due to the dropped stuff but that was happening before already. So, LGTM!

@mydea
mydea merged commit 4c52ba8 into sentry-v2 Oct 27, 2026
24 checks passed
@mydea
mydea deleted the feat/on-mutation-filter branch October 27, 2026 08:16
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.

2 participants