@@ -306,6 +306,15 @@ export function attr(node: Element, attribute: string, value?: string) {
306
306
else if ( node . getAttribute ( attribute ) !== value ) node . setAttribute ( attribute , value ) ;
307
307
}
308
308
309
+ /**
310
+ * List of attributes that should always be set through the attr method,
311
+ * because updating them through the property setter doesn't work reliably.
312
+ * In the example of `width`/`height`, the problem is that the setter only
313
+ * accepts numeric values, but the attribute can also be set to a string like `50%`.
314
+ * If this list becomes too big, rethink this approach.
315
+ */
316
+ const always_set_through_set_attribute = [ 'width' , 'height' ] ;
317
+
309
318
export function set_attributes ( node : Element & ElementCSSInlineStyle , attributes : { [ x : string ] : string } ) {
310
319
// @ts -ignore
311
320
const descriptors = Object . getOwnPropertyDescriptors ( node . __proto__ ) ;
@@ -316,7 +325,7 @@ export function set_attributes(node: Element & ElementCSSInlineStyle, attributes
316
325
node . style . cssText = attributes [ key ] ;
317
326
} else if ( key === '__value' ) {
318
327
( node as any ) . value = node [ key ] = attributes [ key ] ;
319
- } else if ( descriptors [ key ] && descriptors [ key ] . set ) {
328
+ } else if ( descriptors [ key ] && descriptors [ key ] . set && always_set_through_set_attribute . indexOf ( key ) === - 1 ) {
320
329
node [ key ] = attributes [ key ] ;
321
330
} else {
322
331
attr ( node , key , attributes [ key ] ) ;
0 commit comments