diff --git a/.changeset/efficiently-splitCssText-1640.md b/.changeset/efficiently-splitCssText-1640.md new file mode 100644 index 0000000000..57c6d5e6c4 --- /dev/null +++ b/.changeset/efficiently-splitCssText-1640.md @@ -0,0 +1,6 @@ +--- +"rrweb-snapshot": patch +"rrweb": patch +--- + +Improve performance of splitCssText for `; + const style = document.querySelector('style'); + if (style) { + // happydom? bug avoid: strangely a greater than symbol in the template string below + // e.g. '.prose > :last-child' causes more than one child to be appended + style.append(`ass~="not-prose"] *)) { + margin-top: 0; /* cssRules transforms this to '0px' which was preventing matching prior to normalization */ +} + +.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 :where(.prose :last-child):not(:where([class~="not-prose"],[class~="not-prose"] *)) { + margin-bottom: 0; +} + +.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 { + width: 100%; + overflow-wrap: break-word; +} + +.section-home { + height: 100%; + overflow-y: auto; +} +`); + + expect(style.childNodes.length).toEqual(2); + + const expected = [ + '.section-news-v3-detail .news-cnt-wrapper :where(p):not(:where([class~="not-prose"], [class~="not-prose"] *)) { margin-top: 0px; margin-bottom: 0px; }.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 :where(figure):not(:where([class~="not-prose"],[class~="not-prose"] *)) { margin-top: 2em; margin-bottom: 2em; }.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 :where(.prose > :first-child):not(:where([class~="not-prose"],[cl', + 'ass~="not-prose"] *)) { margin-top: 0px; }.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 :where(.prose :last-child):not(:where([class~="not-prose"],[class~="not-prose"] *)) { margin-bottom: 0px; }.section-news-v3-detail .news-cnt-wrapper .plugins-wrapper2 { width: 100%; overflow-wrap: break-word; }.section-home { height: 100%; overflow-y: auto; }', + ]; + const browserSheet = expected.join(''); + expect(stringifyStylesheet(style.sheet!)).toEqual(browserSheet); + let _testNoPxNorm = true; // trigger the original motivating scenario for this test + expect(splitCssText(browserSheet, style, _testNoPxNorm)).toEqual( + expected, + ); + _testNoPxNorm = false; // this case should also be solved by normalizing '0px' -> '0' + expect(splitCssText(browserSheet, style, _testNoPxNorm)).toEqual( + expected, + ); + } + }); + + 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 = + ''; + 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 () {