diff --git a/tracker/tracker/src/main/modules/cssrules.ts b/tracker/tracker/src/main/modules/cssrules.ts index 10a072b4e..8e2217017 100644 --- a/tracker/tracker/src/main/modules/cssrules.ts +++ b/tracker/tracker/src/main/modules/cssrules.ts @@ -17,20 +17,19 @@ export default function (app: App | null) { return } - const sendInserDeleteRule = app.safe( - (stylesheet: CSSStyleSheet, index: number, rule?: string) => { - const sheetID = styleSheetIDMap.get(stylesheet) - if (!sheetID) { - app.debug.warn('No sheedID found', stylesheet, styleSheetIDMap) - return - } - if (typeof rule === 'string') { - app.send(AdoptedSSInsertRuleURLBased(sheetID, rule, index, app.getBaseHref())) - } else { - app.send(AdoptedSSDeleteRule(sheetID, index)) - } - }, - ) + const sendInserDeleteRule = app.safe((sheet: CSSStyleSheet, index: number, rule?: string) => { + const sheetID = styleSheetIDMap.get(sheet) + if (!sheetID) { + app.debug.log('StyleSheet not registered ', sheet, sheet.ownerNode) + // Sheet haven't been registered yet. Rules will be sent on registration. + return + } + if (typeof rule === 'string') { + app.send(AdoptedSSInsertRuleURLBased(sheetID, rule, index, app.getBaseHref())) + } else { + app.send(AdoptedSSDeleteRule(sheetID, index)) + } + }) // TODO: proper rule insertion/removal (how?) const sendReplaceGroupingRule = app.safe((rule: CSSGroupingRule) => { @@ -62,22 +61,22 @@ export default function (app: App | null) { const { insertRule: groupInsertRule, deleteRule: groupDeleteRule } = context.CSSGroupingRule.prototype - context.CSSStyleSheet.prototype.insertRule = function (rule: string, index = 0) { + context.CSSStyleSheet.prototype.insertRule = function (rule: string, index = 0): number { sendInserDeleteRule(this, index, rule) - return insertRule.call(this, rule, index) as number + return insertRule.call(this, rule, index) } - context.CSSStyleSheet.prototype.deleteRule = function (index: number) { + context.CSSStyleSheet.prototype.deleteRule = function (index: number): void { sendInserDeleteRule(this, index) - return deleteRule.call(this, index) as number + return deleteRule.call(this, index) } - context.CSSGroupingRule.prototype.insertRule = function (rule: string, index = 0) { + context.CSSGroupingRule.prototype.insertRule = function (rule: string, index = 0): number { const result = groupInsertRule.call(this, rule, index) as number sendReplaceGroupingRule(this) return result } - context.CSSGroupingRule.prototype.deleteRule = function (index = 0) { - const result = groupDeleteRule.call(this, index) as number + context.CSSGroupingRule.prototype.deleteRule = function (index = 0): void { + const result = groupDeleteRule.call(this, index) as void sendReplaceGroupingRule(this) return result } @@ -102,6 +101,7 @@ export default function (app: App | null) { const sheetID = nextID() styleSheetIDMap.set(sheet, sheetID) app.send(AdoptedSSAddOwner(sheetID, nodeID)) + app.debug.log('StyleSheet registered ', sheet, node) const rules = sheet.cssRules for (let i = 0; i < rules.length; i++) {