Bug 1516287 - Wait for stylesheet to load before adding category colours. r=philipp
--- a/calendar/base/content/calendar-views.js
+++ b/calendar/base/content/calendar-views.js
@@ -458,19 +458,26 @@ var categoryManagement = {
categoryStyleCache: {},
updateStyleSheetForCategory: function(aCatName) {
if (!(aCatName in this.categoryStyleCache)) {
// We haven't created a rule for this category yet, do so now.
let sheet = getViewStyleSheet();
let ruleString = '.category-color-box[categories~="' + aCatName + '"] {} ';
- let ruleIndex = sheet.insertRule(ruleString, sheet.cssRules.length);
- this.categoryStyleCache[aCatName] = sheet.cssRules[ruleIndex];
+ try {
+ let ruleIndex = sheet.insertRule(ruleString, sheet.cssRules.length);
+ this.categoryStyleCache[aCatName] = sheet.cssRules[ruleIndex];
+ } catch (ex) {
+ sheet.ownerNode.addEventListener("load",
+ () => this.updateStyleSheetForCategory(aCatName),
+ { once: true });
+ return;
+ }
}
let color = Preferences.get("calendar.category.color." + aCatName) || "";
this.categoryStyleCache[aCatName].style.backgroundColor = color;
}
};
/**