@@ -130,6 +130,7 @@ export function defineCustomElement(
130
130
const propKeys = rawKeys . map ( camelize )
131
131
132
132
class VueCustomElement extends VueElement {
133
+ static def = Comp
133
134
static get observedAttributes ( ) {
134
135
return attrKeys
135
136
}
@@ -192,13 +193,7 @@ export class VueElement extends BaseClass {
192
193
)
193
194
}
194
195
this . attachShadow ( { mode : 'open' } )
195
- if ( _def . styles ) {
196
- _def . styles . forEach ( css => {
197
- const s = document . createElement ( 'style' )
198
- s . textContent = css
199
- this . shadowRoot ! . appendChild ( s )
200
- } )
201
- }
196
+ this . _applyStyles ( )
202
197
}
203
198
}
204
199
@@ -268,6 +263,16 @@ export class VueElement extends BaseClass {
268
263
vnode . ce = instance => {
269
264
this . _instance = instance
270
265
instance . isCE = true
266
+ // HMR
267
+ if ( __DEV__ ) {
268
+ instance . appContext . reload = ( ) => {
269
+ render ( this . _createVNode ( ) , this . shadowRoot ! )
270
+ this . shadowRoot ! . querySelectorAll ( 'style' ) . forEach ( s => {
271
+ this . shadowRoot ! . removeChild ( s )
272
+ } )
273
+ this . _applyStyles ( )
274
+ }
275
+ }
271
276
272
277
// intercept emit
273
278
instance . emit = ( event : string , ...args : any [ ] ) => {
@@ -293,4 +298,14 @@ export class VueElement extends BaseClass {
293
298
}
294
299
return vnode
295
300
}
301
+
302
+ private _applyStyles ( ) {
303
+ if ( this . _def . styles ) {
304
+ this . _def . styles . forEach ( css => {
305
+ const s = document . createElement ( 'style' )
306
+ s . textContent = css
307
+ this . shadowRoot ! . appendChild ( s )
308
+ } )
309
+ }
310
+ }
296
311
}
0 commit comments