fix: ensure empty string replace/replaceSync clears stylesheets#1774
fix: ensure empty string replace/replaceSync clears stylesheets#1774Juice10 merged 4 commits intorrweb-io:masterfrom
Conversation
|
There was a problem hiding this comment.
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/replaceSyncas present when they arestring(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('')andreplaceSync('').
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Juice10
left a comment
There was a problem hiding this comment.
Thanks for the contribution @alailsonko!
ur welcome |
## 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.
This pull request fixes a bug in the rrweb replayer where clearing an adopted stylesheet using an empty string with
replaceorreplaceSyncdid 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:
Replayerclass to check ifdata.replaceanddata.replaceSyncare of typestringinstead of checking their truthiness, ensuring that empty strings are correctly passed toreplaceandreplaceSyncmethods.Testing improvements:
adopted-style-sheet-empty-replace.tswith event sequences to validate that empty string values forreplaceandreplaceSyncclear stylesheets as intended.replayer.test.tsand added two new test cases to confirm that adopted stylesheets can be cleared usingreplace('')andreplaceSync(''). [1] [2]