Skip to content

Commit

Permalink
avoid using 2nd argument of Array.from that prototype.js does not sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
mdellanoce authored and colingm committed May 1, 2024
1 parent f1e6a51 commit 50d400e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/eleven-bobcats-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rrweb-snapshot': patch
'rrweb': patch
---

avoid using 2nd argument of Array.from that prototype.js does not support
8 changes: 5 additions & 3 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ export function escapeImportStatement(rule: CSSImportRule): string {
export function stringifyStylesheet(s: CSSStyleSheet): string | null {
try {
const rules = s.rules || s.cssRules;
const stringifiedRules = [] as string[];
for (let i = 0; i < rules.length; ++i) {
stringifiedRules.push(stringifyRule(rules[i]));
}
return rules
? fixBrowserCompatibilityIssuesInCSS(
Array.from(rules, stringifyRule).join(''),
)
? fixBrowserCompatibilityIssuesInCSS(stringifiedRules.join(''))
: null;
} catch (error) {
return null;
Expand Down
13 changes: 9 additions & 4 deletions packages/rrweb/src/record/stylesheet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
adoptedStyleSheetParam,
attributeMutation,
mutationCallBack,
styleSheetAddRule,
} from '@rrweb/types';
import { StyleSheetMirror } from '../utils';

Expand Down Expand Up @@ -61,12 +62,16 @@ export class StylesheetManager {
let styleId;
if (!this.styleMirror.has(sheet)) {
styleId = this.styleMirror.add(sheet);
const rules = [] as styleSheetAddRule[];
for (let i = 0; i < sheet.rules.length; ++i) {
rules.push({
rule: stringifyRule(sheet.rules[i]),
index: i,
});
}
styles.push({
styleId,
rules: Array.from(sheet.rules || CSSRule, (r, index) => ({
rule: stringifyRule(r),
index,
})),
rules,
});
} else styleId = this.styleMirror.getId(sheet);
adoptedStyleSheetData.styleIds.push(styleId);
Expand Down

0 comments on commit 50d400e

Please sign in to comment.