Skip to content

fix(record): resync sends only the rules the replayer is missing - #43

Merged
mayberryzane merged 1 commit into
mainfrom
fix/record-resync-diff-by-rule-identity
Oct 14, 2026
Merged

mayberryzane merged 1 commit into
mainfrom
fix/record-resync-diff-by-rule-identity

Conversation

@mayberryzane

@mayberryzane mayberryzane commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #42. When the insertRule patch has been displaced, the resync now sends the replayer only the rules it is missing instead of replacing the whole sheet.

#42 fixed correctness for libraries that insert mid-sheet, but at a cost: any sheet whose rule count changed was deleted and re-sent in full. That also hit libraries that only append (emotion), which the earlier tail re-send handled correctly. And on a page that keeps displacing the patch after we stop repatching, every growing sheet was re-sent in full on each resync tick.

The recorder now keeps, per sheet, the top-level rules the replayer holds, as the live CSSRule objects they were recorded from. Reported inserts and deletes update that list exactly as applyStyleSheetRule applies them (an insert index clamped to the sheet length, an out-of-range delete ignored). CSSOM rule objects keep their identity as rules are inserted around them, so on resync a comparison against sheet.cssRules gives:

  • removes for rules the replayer holds that are no longer live (or are out of live order), highest index first
  • adds for live rules the replayer lacks, at their live index, lowest first

These are sent as two events, because the replayer applies an event's adds before its removes. A sheet first seen while capture was already broken is still replaced in full, since there is nothing to compare against. Healthy ticks skip a sheet whose count matches, as before.

New tests pin the cost as well as the result: a missed append, a missed mid-sheet insert, a missed delete plus insert, and a patch displaced eight times (past the repatch limit) each send exactly the changed rules, and the sheet rebuilt from the events matches the live one. All four fail against the previous commit.

test/record, test/replay and test/replayer.test.ts pass locally (242 passed, 3 skipped).

🤖 Generated with Claude Code


Note

Overview
When the CSSOM insertRule/deleteRule patch is displaced, stylesheet resync no longer wipes and re-sends entire sheets on every tick. The recorder now mirrors what the replayer holds: per-sheet ordered lists of live CSSRule objects, updated on each reported insert/delete the same way applyStyleSheetRule applies them.

On resync, syncReplayerCopy diffs that list against sheet.cssRules—removes stale or out-of-order entries (high index first), then adds missing rules at their live indices (low first), split across two events because adds run before removes. Full replaceReplayerCopy is kept only when a sheet is first seen while capture was already broken.

Tests assert replay fidelity and incremental event cost: missed mid-sheet insert, append-only (emotion-style), missed delete+insert, and repeated patch displacement each emit only the changed rules, not the whole sheet again.

Reviewed by Cursor Bugbot for commit 953b285. Bugbot is set up for automated code reviews on this repo. Configure here.

Track the replayer's copy of each stylesheet as the live CSSRule objects
it was recorded from, and diff by identity on resync instead of replacing
the whole sheet whenever the rule count changed. A missed insert now costs
one rule, appended or mid-sheet, including on pages that keep displacing
the insertRule patch after we stop repatching.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mayberryzane
mayberryzane merged commit 964641c into main Oct 14, 2026
15 checks passed
@mayberryzane
mayberryzane deleted the fix/record-resync-diff-by-rule-identity branch October 14, 2026 20:10
mayberryzane added a commit to launchdarkly/observability-sdk that referenced this pull request Oct 14, 2026
…sing

Bumps rrweb to pick up launchdarkly/rrweb#43.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mayberryzane added a commit to launchdarkly/observability-sdk that referenced this pull request Oct 14, 2026
…sing (#831)

Bumps the rrweb submodule to pick up
[launchdarkly/rrweb#43](launchdarkly/rrweb#43).
When recording recovers CSS-in-JS rules after another script displaced
its `insertRule` patch, it now sends only the rules the replayer is
missing instead of re-sending the whole stylesheet (the behaviour #825
shipped). Pages that keep displacing the patch no longer re-upload every
growing sheet on each resync.

The submodule points at the #43 merge commit,
[964641c](launchdarkly/rrweb@964641cbbe), on
rrweb `main`.

The `@launchdarkly/o11y` suite passes against this commit (509 tests),
including the stylesheet resync test from #829.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Updates the **`rrweb` git submodule** to include
[launchdarkly/rrweb#43](launchdarkly/rrweb#43),
changing how **stylesheet resync** works after another script restores a
pristine `CSSStyleSheet.prototype.insertRule` and displaces the
recorder’s patch.
> 
> On recovery, recording now emits **only the CSS rules the replayer is
missing** instead of re-sending the **entire** stylesheet (the behavior
introduced in #825). That cuts repeated full-sheet uploads on pages that
keep displacing the patch as CSS-in-JS sheets grow.
> 
> No `@launchdarkly/o11y` source changes in this PR—the behavioral fix
lives in the fork; existing coverage includes the stylesheet resync test
from #829.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
fed55ae. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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