Skip to content

fix: ensure empty string replace/replaceSync clears stylesheets#1774

Merged
Juice10 merged 4 commits intorrweb-io:masterfrom
alailsonko:fix/stylesheet-empty-replace
Feb 6, 2026
Merged

fix: ensure empty string replace/replaceSync clears stylesheets#1774
Juice10 merged 4 commits intorrweb-io:masterfrom
alailsonko:fix/stylesheet-empty-replace

Conversation

@alailsonko
Copy link
Contributor

This pull request fixes a bug in the rrweb replayer where clearing an adopted stylesheet using an empty string with replace or replaceSync did not work as expected. The bug occurred because the previous code checked for the truthiness of the value, which skipped empty strings. The fix ensures that empty strings are now correctly handled, allowing stylesheets to be cleared. New tests are also added to verify this behavior.

Bug fix for adopted stylesheet clearing:

  • Updated the Replayer class to check if data.replace and data.replaceSync are of type string instead of checking their truthiness, ensuring that empty strings are correctly passed to replace and replaceSync methods.

Testing improvements:

  • Added a new test file adopted-style-sheet-empty-replace.ts with event sequences to validate that empty string values for replace and replaceSync clear stylesheets as intended.
  • Imported the new test events into replayer.test.ts and added two new test cases to confirm that adopted stylesheets can be cleared using replace('') and replaceSync(''). [1] [2]

Copilot AI review requested due to automatic review settings January 25, 2026 16:32
@changeset-bot
Copy link

changeset-bot bot commented Jan 25, 2026

⚠️ No Changeset found

Latest commit: ad0e703

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes rrweb Replayer handling of constructed stylesheet clearing when replace('') / replaceSync('') are used (empty strings were previously skipped due to truthiness checks).

Changes:

  • Update Replayer stylesheet rule replay logic to treat replace / replaceSync as present when they are string (including empty string).
  • Add new event fixtures covering empty-string replace/replaceSync scenarios.
  • Add two replayer tests asserting adopted stylesheet rules are cleared by replace('') and replaceSync('').

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/rrweb/src/replay/index.ts Updates checks for replace/replaceSync so empty strings are applied.
packages/rrweb/test/events/adopted-style-sheet-empty-replace.ts Adds fixture events that exercise clearing via empty-string replace/replaceSync.
packages/rrweb/test/replayer.test.ts Adds test cases validating adopted stylesheet clearing for both APIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@Juice10 Juice10 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @alailsonko!

@alailsonko
Copy link
Contributor Author

Thanks for the contribution @alailsonko!

ur welcome

@Juice10 Juice10 merged commit ad5ac17 into rrweb-io:master Feb 6, 2026
6 checks passed
pauldambra added a commit to PostHog/posthog-rrweb that referenced this pull request Mar 24, 2026
## Changes

Adopts upstream rrweb [PR #1774](rrweb-io/rrweb#1774).

The replayer checked `if (data.replace)` and `if (data.replaceSync)` which are falsy for empty strings, preventing stylesheet clearing via `replace('')` or `replaceSync('')`. Switches to explicit `typeof` checks so empty strings pass through correctly.

Part of #147.
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.

3 participants