@@ -154,6 +154,7 @@ export class VueElement extends BaseClass {
154154
155155 private _connected = false
156156 private _resolved = false
157+ private _numberProps : Record < string , true > | null = null
157158 private _styles ?: HTMLStyleElement [ ]
158159
159160 constructor (
@@ -179,19 +180,18 @@ export class VueElement extends BaseClass {
179180 this . _setAttr ( this . attributes [ i ] . name )
180181 }
181182 // watch future attr changes
182- const observer = new MutationObserver ( mutations => {
183+ new MutationObserver ( mutations => {
183184 for ( const m of mutations ) {
184185 this . _setAttr ( m . attributeName ! )
185186 }
186- } )
187- observer . observe ( this , { attributes : true } )
187+ } ) . observe ( this , { attributes : true } )
188188 }
189189
190190 connectedCallback ( ) {
191191 this . _connected = true
192192 if ( ! this . _instance ) {
193193 this . _resolveDef ( )
194- render ( this . _createVNode ( ) , this . shadowRoot ! )
194+ this . _update ( )
195195 }
196196 }
197197
@@ -215,15 +215,33 @@ export class VueElement extends BaseClass {
215215
216216 const resolve = ( def : InnerComponentDef ) => {
217217 this . _resolved = true
218+ const { props, styles } = def
219+ const hasOptions = ! isArray ( props )
220+ const rawKeys = props ? ( hasOptions ? Object . keys ( props ) : props ) : [ ]
221+
222+ // cast Number-type props set before resolve
223+ let numberProps
224+ if ( hasOptions ) {
225+ for ( const key in this . _props ) {
226+ const opt = props [ key ]
227+ if ( opt === Number || ( opt && opt . type === Number ) ) {
228+ this . _props [ key ] = toNumber ( this . _props [ key ] )
229+ ; ( numberProps || ( numberProps = Object . create ( null ) ) ) [ key ] = true
230+ }
231+ }
232+ }
233+ if ( numberProps ) {
234+ this . _numberProps = numberProps
235+ this . _update ( )
236+ }
237+
218238 // check if there are props set pre-upgrade or connect
219239 for ( const key of Object . keys ( this ) ) {
220240 if ( key [ 0 ] !== '_' ) {
221241 this . _setProp ( key , this [ key as keyof this] )
222242 }
223243 }
224- const { props, styles } = def
225244 // defining getter/setters on prototype
226- const rawKeys = props ? ( isArray ( props ) ? props : Object . keys ( props ) ) : [ ]
227245 for ( const key of rawKeys . map ( camelize ) ) {
228246 Object . defineProperty ( this , key , {
229247 get ( ) {
@@ -246,7 +264,11 @@ export class VueElement extends BaseClass {
246264 }
247265
248266 protected _setAttr ( key : string ) {
249- this . _setProp ( camelize ( key ) , toNumber ( this . getAttribute ( key ) ) , false )
267+ let value = this . getAttribute ( key )
268+ if ( this . _numberProps && this . _numberProps [ key ] ) {
269+ value = toNumber ( value )
270+ }
271+ this . _setProp ( camelize ( key ) , value , false )
250272 }
251273
252274 /**
@@ -263,7 +285,7 @@ export class VueElement extends BaseClass {
263285 if ( val !== this . _props [ key ] ) {
264286 this . _props [ key ] = val
265287 if ( this . _instance ) {
266- render ( this . _createVNode ( ) , this . shadowRoot ! )
288+ this . _update ( )
267289 }
268290 // reflect
269291 if ( shouldReflect ) {
@@ -278,6 +300,10 @@ export class VueElement extends BaseClass {
278300 }
279301 }
280302
303+ private _update ( ) {
304+ render ( this . _createVNode ( ) , this . shadowRoot ! )
305+ }
306+
281307 private _createVNode ( ) : VNode < any , any > {
282308 const vnode = createVNode ( this . _def , extend ( { } , this . _props ) )
283309 if ( ! this . _instance ) {
@@ -298,7 +324,7 @@ export class VueElement extends BaseClass {
298324 if ( ! ( this . _def as ComponentOptions ) . __asyncLoader ) {
299325 // reload
300326 this . _instance = null
301- render ( this . _createVNode ( ) , this . shadowRoot ! )
327+ this . _update ( )
302328 }
303329 }
304330 }
0 commit comments