Ver código fonte

don't insert empty stylesheet

Gildas 7 anos atrás
pai
commit
408d3b795a
1 arquivos alterados com 9 adições e 7 exclusões
  1. 9 7
      lib/single-file/single-file-core.js

+ 9 - 7
lib/single-file/single-file-core.js

@@ -632,13 +632,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 						stylesheetContent += stylesContent + "}";
 					}
 				});
-				const styleElement = this.doc.createElement("style");
-				styleElement.textContent = stylesheetContent;
-				const existingStyleElement = this.doc.querySelector("style");
-				if (existingStyleElement) {
-					existingStyleElement.parentElement.insertBefore(styleElement, existingStyleElement);
-				} else {
-					this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+				if (stylesheetContent) {
+					const styleElement = this.doc.createElement("style");
+					styleElement.textContent = stylesheetContent;
+					const existingStyleElement = this.doc.querySelector("style");
+					if (existingStyleElement) {
+						existingStyleElement.parentElement.insertBefore(styleElement, existingStyleElement);
+					} else {
+						this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+					}
 				}
 			}
 		}