(rule, index)
| 105 | } |
| 106 | |
| 107 | insertRule(rule, index) { |
| 108 | invariant(isString(rule), '`insertRule` accepts only strings') |
| 109 | |
| 110 | if (typeof window === 'undefined') { |
| 111 | if (typeof index !== 'number') { |
| 112 | index = this._serverSheet.cssRules.length |
| 113 | } |
| 114 | |
| 115 | this._serverSheet.insertRule(rule, index) |
| 116 | return this._rulesCount++ |
| 117 | } |
| 118 | |
| 119 | if (this._optimizeForSpeed) { |
| 120 | const sheet = this.getSheet() |
| 121 | if (typeof index !== 'number') { |
| 122 | index = sheet.cssRules.length |
| 123 | } |
| 124 | |
| 125 | // this weirdness for perf, and chrome's weird bug |
| 126 | // https://stackoverflow.com/questions/20007992/chrome-suddenly-stopped-accepting-insertrule |
| 127 | try { |
| 128 | sheet.insertRule(rule, index) |
| 129 | } catch (error) { |
| 130 | if (!isProd) { |
| 131 | console.warn( |
| 132 | `StyleSheet: illegal rule: \n\n${rule}\n\nSee https://stackoverflow.com/q/20007992 for more info` |
| 133 | ) |
| 134 | } |
| 135 | |
| 136 | return -1 |
| 137 | } |
| 138 | } else { |
| 139 | const insertionPoint = this._tags[index] |
| 140 | this._tags.push(this.makeStyleTag(this._name, rule, insertionPoint)) |
| 141 | } |
| 142 | |
| 143 | return this._rulesCount++ |
| 144 | } |
| 145 | |
| 146 | replaceRule(index, rule) { |
| 147 | if (this._optimizeForSpeed || typeof window === 'undefined') { |
no test coverage detected