chore: warn style injection in shadowRoot: false mode

This commit is contained in:
Evan You 2024-08-05 16:33:05 +08:00
parent e94b01bd8a
commit 6e541db29f
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 9 additions and 1 deletions

View File

@ -312,6 +312,12 @@ export class VueElement extends BaseClass {
} }
// apply CSS // apply CSS
if (__DEV__ && styles && def.shadowRoot === false) {
warn(
'Custom element style injection is not supported when using ' +
'shadowRoot: false',
)
}
this._applyStyles(styles) this._applyStyles(styles)
// initial render // initial render
@ -481,11 +487,13 @@ export class VueElement extends BaseClass {
} }
private _applyStyles(styles: string[] | undefined) { private _applyStyles(styles: string[] | undefined) {
const root = this.shadowRoot
if (!root) return
if (styles) { if (styles) {
styles.forEach(css => { styles.forEach(css => {
const s = document.createElement('style') const s = document.createElement('style')
s.textContent = css s.textContent = css
this._root.appendChild(s) root.appendChild(s)
// record for HMR // record for HMR
if (__DEV__) { if (__DEV__) {
;(this._styles || (this._styles = [])).push(s) ;(this._styles || (this._styles = [])).push(s)