From 4f9a15eced22021b3b78b16eba1a750da742f48d Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Sat, 14 Nov 2020 18:05:40 +0100 Subject: [PATCH] slightly improve output size by refactoring add_css method --- src/compiler/compile/render_dom/index.ts | 2 +- src/runtime/internal/dom.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 4db7a6815a..22eacde32b 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -45,7 +45,7 @@ export default function dom( if (should_add_css) { body.push(b` function ${add_css}(customStyleTag) { - @appendStyleIfNotPresent(customStyleTag || @_document.head, "${component.stylesheet.id}-style", "${styles}"); + @appendStyleIfNotPresent(customStyleTag, "${component.stylesheet.id}", "${styles}"); } `); } diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 94214eef02..ed665427d0 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -1,6 +1,10 @@ import { has_prop } from './utils'; -export function appendStyleIfNotPresent(target: Element, styleId: string, styles: string) { +export function appendStyleIfNotPresent( + target: Element = document.head, + styleSheetId: string, + styles: string, + styleId:string = styleSheetId + '-style') { if (!target.querySelector('#' + styleId)) { const style = element('style'); style.id = styleId;