@@ -186,6 +186,10 @@ export class VueElement extends BaseClass {
186
186
)
187
187
}
188
188
this . attachShadow ( { mode : 'open' } )
189
+ if ( ! ( this . _def as ComponentOptions ) . __asyncLoader ) {
190
+ // for sync component defs we can immediately resolve props
191
+ this . _resolveProps ( this . _def )
192
+ }
189
193
}
190
194
}
191
195
@@ -227,9 +231,8 @@ export class VueElement extends BaseClass {
227
231
}
228
232
} ) . observe ( this , { attributes : true } )
229
233
230
- const resolve = ( def : InnerComponentDef ) => {
234
+ const resolve = ( def : InnerComponentDef , isAsync = false ) => {
231
235
const { props, styles } = def
232
- const declaredPropKeys = isArray ( props ) ? props : Object . keys ( props || { } )
233
236
234
237
// cast Number-type props set before resolve
235
238
let numberProps
@@ -248,23 +251,10 @@ export class VueElement extends BaseClass {
248
251
}
249
252
this . _numberProps = numberProps
250
253
251
- // check if there are props set pre-upgrade or connect
252
- for ( const key of Object . keys ( this ) ) {
253
- if ( key [ 0 ] !== '_' && declaredPropKeys . includes ( key ) ) {
254
- this . _setProp ( key , this [ key as keyof this] , true , false )
255
- }
256
- }
257
-
258
- // defining getter/setters on prototype
259
- for ( const key of declaredPropKeys . map ( camelize ) ) {
260
- Object . defineProperty ( this , key , {
261
- get ( ) {
262
- return this . _getProp ( key )
263
- } ,
264
- set ( val ) {
265
- this . _setProp ( key , val )
266
- }
267
- } )
254
+ if ( isAsync ) {
255
+ // defining getter/setters on prototype
256
+ // for sync defs, this already happened in the constructor
257
+ this . _resolveProps ( def )
268
258
}
269
259
270
260
// apply CSS
@@ -276,12 +266,36 @@ export class VueElement extends BaseClass {
276
266
277
267
const asyncDef = ( this . _def as ComponentOptions ) . __asyncLoader
278
268
if ( asyncDef ) {
279
- asyncDef ( ) . then ( resolve )
269
+ asyncDef ( ) . then ( def => resolve ( def , true ) )
280
270
} else {
281
271
resolve ( this . _def )
282
272
}
283
273
}
284
274
275
+ private _resolveProps ( def : InnerComponentDef ) {
276
+ const { props } = def
277
+ const declaredPropKeys = isArray ( props ) ? props : Object . keys ( props || { } )
278
+
279
+ // check if there are props set pre-upgrade or connect
280
+ for ( const key of Object . keys ( this ) ) {
281
+ if ( key [ 0 ] !== '_' && declaredPropKeys . includes ( key ) ) {
282
+ this . _setProp ( key , this [ key as keyof this] , true , false )
283
+ }
284
+ }
285
+
286
+ // defining getter/setters on prototype
287
+ for ( const key of declaredPropKeys . map ( camelize ) ) {
288
+ Object . defineProperty ( this , key , {
289
+ get ( ) {
290
+ return this . _getProp ( key )
291
+ } ,
292
+ set ( val ) {
293
+ this . _setProp ( key , val )
294
+ }
295
+ } )
296
+ }
297
+ }
298
+
285
299
protected _setAttr ( key : string ) {
286
300
let value = this . getAttribute ( key )
287
301
const camelKey = camelize ( key )
0 commit comments