Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

clipper: delete import css rules after iteration (#3720)

Muhammad Ali37d8d85935f9
diff --git a/packages/clipper/src/styles.ts b/packages/clipper/src/styles.ts
index edf8cba93..79e71da97 100644
--- a/packages/clipper/src/styles.ts
+++ b/packages/clipper/src/styles.ts
@@ -87,23 +87,26 @@ export async function inlineStylesheets(options?: FetchOptions) {
}
async function resolveImports(options?: FetchOptions) {
- let index = 0;
for (const sheet of document.styleSheets) {
+ const rulesToDelete = [];
if (skipStyleSheet(sheet)) continue;
- for (const rule of sheet.cssRules) {
+ for (let i = 0; i < sheet.cssRules.length; ++i) {
+ const rule = sheet.cssRules.item(i);
+ if (!rule) continue;
+
if (rule.type === CSSRule.IMPORT_RULE) {
const href = (rule as CSSImportRule).href;
const result = await downloadStylesheet(href, options);
if (result) {
if (sheet.ownerNode) sheet.ownerNode.before(result);
else document.head.appendChild(result);
-
- sheet.deleteRule(index);
+ rulesToDelete.push(i);
}
}
- ++index;
}
+
+ for (const ruleIndex of rulesToDelete) sheet.deleteRule(ruleIndex);
}
}