Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix a case I previously forgot about, when there are multiple matches…
… and we end up not finding a unique one - we should just go with the first one (note: this is still not binary search so could exhibit pathological behaviour)
  • Loading branch information
eoghanmurray committed Jan 29, 2025
commit 5962d0398a7e147faf02c3e3aeb19594e949b723
3 changes: 3 additions & 0 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ export function splitCssText(
) {
// this childNode has same starting content as previous
splitNorm = cssTextNorm.indexOf(bit, 1);
} else if (j === textContentNorm.length - 1) {
// we're about to end loop without a split point
splitNorm = cssTextNorm.indexOf(bit);
}
if (splitNorm !== -1) {
// find the split point in the original text
Expand Down
26 changes: 25 additions & 1 deletion packages/rrweb-snapshot/test/css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ describe('css splitter', () => {
transition: all 4s ease;
}`),
);
// TODO: splitCssText can't handle it yet if both start with .x
style.appendChild(
JSDOM.fragment(`.y {
-moz-transition: all 5s ease;
Expand Down Expand Up @@ -227,6 +226,31 @@ describe('css splitter', () => {
}
expect(splitCssText(cssText, style)).toEqual(sections);
});

it('finds css textElement splits correctly, even with repeated sections', () => {
const window = new Window({ url: 'https://localhost:8080' });
const document = window.document;
document.head.innerHTML = '<style>.a{background-color: black; } </style>';
const style = document.querySelector('style');
if (style) {
style.append('.x{background-color:red;}');
style.append('.b {background-color:black;}');
style.append('.x{background-color:red;}');
style.append('.c{ background-color: black}');

const expected = [
'.a { background-color: black; }',
'.x { background-color: red; }',
'.b { background-color: black; }',
'.x { background-color: red; }',
'.c { background-color: black; }',
];
const browserSheet = expected.join('');
expect(stringifyStylesheet(style.sheet!)).toEqual(browserSheet);

expect(splitCssText(browserSheet, style)).toEqual(expected);
}
});
});

describe('applyCssSplits css rejoiner', function () {
Expand Down