#3940 refactor check if style is already present

pull/5639/head
Ivan Hofer 5 years ago
parent f2221fc873
commit 9ad664e1d2

@ -45,13 +45,7 @@ export default function dom(
if (should_add_css) {
body.push(b`
function ${add_css}(customStyleTag) {
const styleId = "${component.stylesheet.id}-style"
const appendTo = customStyleTag || @_document.head
if (appendTo.querySelector(styleId)) return
var style = @element("style");
style.id = styleId;
style.textContent = "${styles}";
@append(appendTo, style);
@appendStyleIfNotPresent(customStyleTag || @_document.head, "${component.stylesheet.id}-style", "${styles}");
}
`);
}

@ -1,5 +1,14 @@
import { has_prop } from './utils';
export function appendStyleIfNotPresent(target: Element, styleId: string, styles: string) {
if (!target.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;
style.textContent = styles;
append(target, style);
}
}
export function append(target: Node, node: Node) {
target.appendChild(node);
}

Loading…
Cancel
Save