Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Perf: Avoid creation of intermediary array when iterating over styles…
…heet rules by using the second `mapFn` argument of Array.from

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
  • Loading branch information
eoghanmurray committed Aug 14, 2023
commit 6ac581ba454f7e414bf090ce78ea19db50ee26ad
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function stringifyStylesheet(s: CSSStyleSheet): string | null {
const rules = s.rules || s.cssRules;
return rules
? fixBrowserCompatibilityIssuesInCSS(
Array.from(rules).map(stringifyRule).join(''),
Array.from(rules, stringifyRule).join(''),
)
: null;
} catch (error) {
Expand Down
11 changes: 4 additions & 7 deletions packages/rrweb/src/record/stylesheet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ export class StylesheetManager {
let styleId;
if (!this.styleMirror.has(sheet)) {
styleId = this.styleMirror.add(sheet);
const rules = Array.from(sheet.rules || CSSRule);
styles.push({
styleId,
rules: rules.map((r, index) => {
return {
rule: stringifyRule(r),
index,
};
}),
rules: Array.from(sheet.rules || CSSRule, (r, index) => ({
rule: stringifyRule(r),
index,
})),
});
} else styleId = this.styleMirror.getId(sheet);
adoptedStyleSheetData.styleIds.push(styleId);
Expand Down