Skip to content

Collapse multiple text/attribute mutations when throttled (or frozen) & add per-element throttling config - #1933

Open
eoghanmurray wants to merge 16 commits into
mainfrom
collapse-frozen-mutations
Open

eoghanmurray wants to merge 16 commits into
mainfrom
collapse-frozen-mutations

Conversation

@eoghanmurray

@eoghanmurray eoghanmurray commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

This PR does two things:

  • Ensure we don't emit multiple text or attribute mutations against the same node while throttled or when mutations are frozen
  • Pull in the 'configurable throttling on mutation emission' from Implement configurable throttling on mutation emission #1694 but re-implement on a per-element basis, so a change to a well behaved element isn't delayed by another noisier one

Replay should be unaffected, as the replayer would have applied the last mutation in the series, which should end up in the same state at that timestamp. The test data shows some de-duplication of text/attributes after this change, which is proof positive.

Tech note:

  • Also recognize that the additional WeakMap added in perf(rrweb): attribute mutation optimization #1343 in relation to attributes/attributeMap can be improved by replacing both variables with a single Map. The array was holding strong references to the Node anyway in the attributeCursor; these were freed at the end after // reset and this is still the case after this change

@changeset-bot

changeset-bot Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 29a4ec8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
rrweb Patch
@rrweb/record Patch
@rrweb/types Patch
@rrweb/all Patch
@rrweb/browser-client Patch
@rrweb/packer Patch
@rrweb/replay Patch
rrdom-nodejs Patch
rrdom Patch
rrvideo Patch
rrweb-player Patch
rrweb-snapshot Patch
@rrweb/utils Patch
@rrweb/web-extension Patch
@rrweb/rrweb-plugin-canvas-webrtc-record Patch
@rrweb/rrweb-plugin-canvas-webrtc-replay Patch
@rrweb/rrweb-plugin-console-record Patch
@rrweb/rrweb-plugin-console-replay Patch
@rrweb/rrweb-plugin-network-record Patch
@rrweb/rrweb-plugin-network-replay Patch
@rrweb/rrweb-plugin-sequential-id-record Patch
@rrweb/rrweb-plugin-sequential-id-replay Patch

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

@eoghanmurray
eoghanmurray force-pushed the collapse-frozen-mutations branch from ce9ff62 to 179b3f9 Compare September 8, 2026 12:04
@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Changes

Size change: +1.42 kB (+0.01%) | Total size: 10430.46 kB

all - 1975.72 kB -> 1976.08 kB (+364 B (+0.02%))
File Base PR Diff
all.cjs 567.91 kB 568.03 kB +121 B (+0.02%)
all.js 567.58 kB 567.70 kB +121 B (+0.02%)
all.umd.cjs 571.12 kB 571.24 kB +121 B (+0.02%)
all.umd.min.cjs 269.12 kB 269.12 kB +1 B (+0.00%)
browser-client - 670.07 kB -> 670.42 kB (+364 B (+0.05%))
File Base PR Diff
browser-client.cjs 192.15 kB 192.26 kB +121 B (+0.06%)
browser-client.js 191.92 kB 192.04 kB +121 B (+0.06%)
browser-client.umd.cjs 194.97 kB 195.09 kB +121 B (+0.06%)
browser-client.umd.min.cjs 91.03 kB 91.03 kB +1 B (+0.00%)
record - 552.68 kB -> 553.04 kB (+364 B (+0.06%))
File Base PR Diff
record.cjs 158.46 kB 158.58 kB +121 B (+0.07%)
record.js 158.38 kB 158.49 kB +121 B (+0.07%)
record.umd.cjs 159.79 kB 159.91 kB +121 B (+0.07%)
record.umd.min.cjs 76.05 kB 76.06 kB +1 B (+0.00%)
rrweb - 1913.90 kB -> 1914.26 kB (+364 B (+0.02%))
File Base PR Diff
rrweb.cjs 551.07 kB 551.19 kB +121 B (+0.02%)
rrweb.js 550.77 kB 550.89 kB +121 B (+0.02%)
rrweb.umd.cjs 552.29 kB 552.41 kB +121 B (+0.02%)
rrweb.umd.min.cjs 259.77 kB 259.78 kB +1 B (+0.00%)

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
@rrweb/all

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/all@29a4ec8

@rrweb/browser-client

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/browser-client@29a4ec8

@rrweb/packer

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/packer@29a4ec8

@rrweb/record

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/record@29a4ec8

@rrweb/replay

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/replay@29a4ec8

rrdom

npm i https://pkg.pr.new/rrweb-io/rrweb/rrdom@29a4ec8

rrdom-nodejs

npm i https://pkg.pr.new/rrweb-io/rrweb/rrdom-nodejs@29a4ec8

rrvideo

npm i https://pkg.pr.new/rrweb-io/rrweb/rrvideo@29a4ec8

rrweb

npm i https://pkg.pr.new/rrweb-io/rrweb@29a4ec8

rrweb-player

npm i https://pkg.pr.new/rrweb-io/rrweb/rrweb-player@29a4ec8

rrweb-snapshot

npm i https://pkg.pr.new/rrweb-io/rrweb/rrweb-snapshot@29a4ec8

@rrweb/types

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/types@29a4ec8

@rrweb/utils

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/utils@29a4ec8

@rrweb/rrweb-plugin-canvas-webrtc-record

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-canvas-webrtc-record@29a4ec8

@rrweb/rrweb-plugin-canvas-webrtc-replay

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-canvas-webrtc-replay@29a4ec8

@rrweb/rrweb-plugin-console-record

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-console-record@29a4ec8

@rrweb/rrweb-plugin-console-replay

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-console-replay@29a4ec8

@rrweb/rrweb-plugin-network-record

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-network-record@29a4ec8

@rrweb/rrweb-plugin-network-replay

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-network-replay@29a4ec8

@rrweb/rrweb-plugin-sequential-id-record

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-sequential-id-record@29a4ec8

@rrweb/rrweb-plugin-sequential-id-replay

npm i https://pkg.pr.new/rrweb-io/rrweb/@rrweb/rrweb-plugin-sequential-id-replay@29a4ec8

commit: 29a4ec8

…e e.g. style attribute diffs over and over while frozen or during throttling

 - this mirrors the other pattern from this PR for text mutations
 - more importantly, the serialization of new 'add' nodes has always happened upon emission, so the deferred computation is by design (no point in serializing something that may have been added then quickly removed)
…`sampling.mutation` ms setting

 - can prevent overly frequent (javascript based) animation per second on the same attribute; the mutation buffer will emit a single change at the end if throttled changes are against the same element
…default in rrweb package; useful for experimenting with live-stream in worktrees where there's been no previous build
… attributes/textContent on a per-element basis rather than globally (so a noisy element can't delay a well behaved one)
@eoghanmurray
eoghanmurray force-pushed the collapse-frozen-mutations branch from 365f778 to 49c6e6c Compare September 21, 2026 22:00
@eoghanmurray eoghanmurray changed the title Collapse multiple text mutations when frozen / throttled Collapse multiple text/attribute mutations when throttled (or frozen) & add per-element throttling config Sep 24, 2026
eoghanmurray and others added 3 commits September 24, 2026 13:30
The 'error-handler' test ("triggers for errors from mutation observer")
hung. Since attributes are now resolved lazily at emit time
(resolveAttributes reads getAttribute), a throw there escaped emit before
the buffer was consumed, leaving the offending node in attributesMap. It
then re-threw on the next emit — and because the errorHandler writes to
the DOM, that triggered a fresh mutation → emit → re-throw → unbounded
loop. Even without a DOM-mutating handler, one bad node would poison
every subsequent emit and kill recording for the page.

Consume the texts/attributes maps (swap in the held maps) before building
the payload, so a throw during resolveAttributes can't leave the entry
behind: the error still reaches the errorHandler once, and recording
continues on the next mutation.

Update the test's expected message (m.target.getAttribute →
target.getAttribute) since the throwing call moved from processMutation
to resolveAttributes.
… a delayed mutation emission is short circuit triggered by another event (another type of forcing)
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.

1 participant