Skip to content
Merged
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
Don't go past 100 iterations trying to find a unique substring
  • Loading branch information
eoghanmurray committed Jan 29, 2025
commit 3a452e339c2a47d90408dd1f8c9f4e40a1d7b6ba
16 changes: 10 additions & 6 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* Browsers sometimes incorrectly escape `@import` on `.cssText` statements.
* This function tries to correct the escaping.
* more info: https://bugs.chromium.org/p/chromium/issues/detail?id=1472259
* @param cssImportRule

Check warning on line 83 in packages/rrweb-snapshot/src/utils.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/utils.ts#L83

[tsdoc/syntax] tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen
* @returns `cssText` with browser inconsistencies fixed, or null if not applicable.
*/
export function escapeImportStatement(rule: CSSImportRule): string {
Expand Down Expand Up @@ -474,7 +474,7 @@
): string[] {
const childNodes = Array.from(style.childNodes);
const splits: string[] = [];
let iterLimit = 0;
let iterCount = 0;
if (childNodes.length > 1 && cssText && typeof cssText === 'string') {
let cssTextNorm = normalizeCssString(cssText, _testNoPxNorm);
const normFactor = cssTextNorm.length / cssText.length;
Expand All @@ -484,9 +484,10 @@
typeof childNodes[i].textContent === 'string'
) {
const textContentNorm = normalizeCssString(
childNodes[i].textContent!,

Check warning on line 487 in packages/rrweb-snapshot/src/utils.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/utils.ts#L487

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
_testNoPxNorm,
);
const jLimit = 100; // how many iterations for the first part of searching
let j = 3;
for (; j < textContentNorm.length; j++) {
if (
Expand Down Expand Up @@ -525,6 +526,12 @@
splits.push(cssText);
return splits;
}
j = jLimit + 1; // trigger end of search
} else if (j === textContentNorm.length - 1) {
// we're about to end loop without a split point
splitNorm = cssTextNorm.indexOf(startSubstring);
}
if (cssNormSplits.length >= 2 && j > jLimit) {
const prevTextContent = childNodes[i - 1].textContent;
if (prevTextContent && typeof prevTextContent === 'string') {
// pick the first matching point which respects the previous chunk's approx size
Expand All @@ -535,16 +542,13 @@
// fall back to pick the first matching point of many
splitNorm = cssNormSplits[0].length;
}
} else if (j === textContentNorm.length - 1) {
// we're about to end loop without a split point
splitNorm = cssTextNorm.indexOf(startSubstring);
}
if (splitNorm !== -1) {
// find the split point in the original text
let k = Math.floor(splitNorm / normFactor);
for (; k > 0 && k < cssText.length; ) {
iterLimit += 1;
if (iterLimit > 50 * childNodes.length) {
iterCount += 1;
if (iterCount > 50 * childNodes.length) {
// quit for performance purposes
splits.push(cssText);
return splits;
Expand Down
Loading