Bug 1516287 - Wait for stylesheet to load before adding category colours. r+a=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 26 Dec 2018 10:55:59 +1300
changeset 33053 8b4c9d319ddbade1ba70963fe7acb8416dccd99e
parent 33052 8e53a70093a9727303bed0bba44eb795a981cc54
child 33054 9bbb544328750cbd12329a726ccc85bde15ac846
push id2354
push usermozilla@jorgk.com
push dateMon, 31 Dec 2018 16:53:09 +0000
treeherdercomm-beta@0fc0c5dd8de5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1516287
Bug 1516287 - Wait for stylesheet to load before adding category colours. r+a=philipp
calendar/base/content/calendar-views.js
--- 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;
     }
 };
 
 /**