Skip to content

Commit

Permalink
insertRule fallback on global styles too
Browse files Browse the repository at this point in the history
  • Loading branch information
dburles committed May 13, 2020
1 parent 5176cd9 commit 0dea14b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/css/createCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ const createCache = () => {
if (canCommit(hash)) {
transformedCSSArray.forEach((transformedCSS) => {
const rule = transformedCSSToClass(transformedCSS);

const insertTextNode = () => {
element.appendChild(document.createTextNode(rule));
};

if (isServer) {
serverStyles += rule;
} else {
if (isDevelopment) {
element.appendChild(document.createTextNode(rule));
insertTextNode();
} else {
element.sheet.insertRule(rule, element.sheet.cssRules.length);
try {
element.sheet.insertRule(rule, element.sheet.cssRules.length);
} catch (error) {
insertTextNode();
}
}
}
});
Expand Down

0 comments on commit 0dea14b

Please sign in to comment.