@@ -173,6 +173,10 @@ export class VueElement extends BaseClass {
173
173
)
174
174
}
175
175
this . attachShadow ( { mode : 'open' } )
176
+ if ( ! ( this . _def as ComponentOptions ) . __asyncLoader ) {
177
+ // for sync component defs we can immediately resolve props
178
+ this . _resolveProps ( this . _def )
179
+ }
176
180
}
177
181
}
178
182
@@ -214,10 +218,9 @@ export class VueElement extends BaseClass {
214
218
}
215
219
} ) . observe ( this , { attributes : true } )
216
220
217
- const resolve = ( def : InnerComponentDef ) => {
218
- const { props, styles } = def
221
+ const resolve = ( def : InnerComponentDef , isAsync = false ) => {
222
+ const { props = [ ] , styles } = def
219
223
const hasOptions = ! isArray ( props )
220
- const rawKeys = props ? ( hasOptions ? Object . keys ( props ) : props ) : [ ]
221
224
222
225
// cast Number-type props set before resolve
223
226
let numberProps
@@ -232,23 +235,10 @@ export class VueElement extends BaseClass {
232
235
}
233
236
this . _numberProps = numberProps
234
237
235
- // check if there are props set pre-upgrade or connect
236
- for ( const key of Object . keys ( this ) ) {
237
- if ( key [ 0 ] !== '_' ) {
238
- this . _setProp ( key , this [ key as keyof this] , true , false )
239
- }
240
- }
241
-
242
- // defining getter/setters on prototype
243
- for ( const key of rawKeys . map ( camelize ) ) {
244
- Object . defineProperty ( this , key , {
245
- get ( ) {
246
- return this . _getProp ( key )
247
- } ,
248
- set ( val ) {
249
- this . _setProp ( key , val )
250
- }
251
- } )
238
+ if ( isAsync ) {
239
+ // defining getter/setters on prototype
240
+ // for sync defs, this already happened in the constructor
241
+ this . _resolveProps ( def )
252
242
}
253
243
254
244
// apply CSS
@@ -260,12 +250,37 @@ export class VueElement extends BaseClass {
260
250
261
251
const asyncDef = ( this . _def as ComponentOptions ) . __asyncLoader
262
252
if ( asyncDef ) {
263
- asyncDef ( ) . then ( resolve )
253
+ asyncDef ( ) . then ( def => resolve ( def , true ) )
264
254
} else {
265
255
resolve ( this . _def )
266
256
}
267
257
}
268
258
259
+ private _resolveProps ( def : InnerComponentDef ) {
260
+ // check if there are props set pre-upgrade or connect
261
+ for ( const key of Object . keys ( this ) ) {
262
+ if ( key [ 0 ] !== '_' ) {
263
+ this . _setProp ( key , this [ key as keyof this] , true , false )
264
+ }
265
+ }
266
+
267
+ const { props } = def
268
+ const hasOptions = ! isArray ( props )
269
+ const rawKeys = props ? ( hasOptions ? Object . keys ( props ) : props ) : [ ]
270
+
271
+ // defining getter/setters on prototype
272
+ for ( const key of rawKeys . map ( camelize ) ) {
273
+ Object . defineProperty ( this , key , {
274
+ get ( ) {
275
+ return this . _getProp ( key )
276
+ } ,
277
+ set ( val ) {
278
+ this . _setProp ( key , val )
279
+ }
280
+ } )
281
+ }
282
+ }
283
+
269
284
protected _setAttr ( key : string ) {
270
285
let value = this . getAttribute ( key )
271
286
if ( this . _numberProps && this . _numberProps [ key ] ) {
0 commit comments