From: Evan You Date: Mon, 5 Aug 2024 08:33:05 +0000 (+0800) Subject: chore: warn style injection in shadowRoot: false mode X-Git-Tag: v3.5.0-beta.1~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e541db29f091e985bde6f483850561980b657eb;p=thirdparty%2Fvuejs%2Fcore.git chore: warn style injection in shadowRoot: false mode --- diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index add2092574..bb73feccff 100644 --- a/packages/runtime-dom/src/apiCustomElement.ts +++ b/packages/runtime-dom/src/apiCustomElement.ts @@ -312,6 +312,12 @@ export class VueElement extends BaseClass { } // apply CSS + if (__DEV__ && styles && def.shadowRoot === false) { + warn( + 'Custom element style injection is not supported when using ' + + 'shadowRoot: false', + ) + } this._applyStyles(styles) // initial render @@ -481,11 +487,13 @@ export class VueElement extends BaseClass { } private _applyStyles(styles: string[] | undefined) { + const root = this.shadowRoot + if (!root) return if (styles) { styles.forEach(css => { const s = document.createElement('style') s.textContent = css - this._root.appendChild(s) + root.appendChild(s) // record for HMR if (__DEV__) { ;(this._styles || (this._styles = [])).push(s)