Bug 1516287 - Wait for stylesheet to load before adding category colours. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 26 Dec 2018 10:55:59 +1300
changeset 33208 e8fcc4360ac4
parent 33207 9211c27bcce1
child 33209 b3f44f8462f9
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1516287
Bug 1516287 - Wait for stylesheet to load before adding category colours. r=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;
     }
 };
 
 /**