@@ -81,8 +81,6 @@ export function set_checked(element, checked) {
81
81
* @param {boolean } [skip_warning]
82
82
*/
83
83
export function set_attribute ( element , attribute , value , skip_warning ) {
84
- value = value == null ? null : value + '' ;
85
-
86
84
// @ts -expect-error
87
85
var attributes = ( element . __attributes ??= { } ) ;
88
86
@@ -95,7 +93,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
95
93
( attribute === 'href' && element . nodeName === 'LINK' )
96
94
) {
97
95
if ( ! skip_warning ) {
98
- check_src_in_dev_hydration ( element , attribute , value ) ;
96
+ check_src_in_dev_hydration ( element , attribute , value ?? '' ) ;
99
97
}
100
98
101
99
// If we reset these attributes, they would result in another network request, which we want to avoid.
@@ -113,8 +111,11 @@ export function set_attribute(element, attribute, value, skip_warning) {
113
111
element [ LOADING_ATTR_SYMBOL ] = value ;
114
112
}
115
113
116
- if ( value === null ) {
114
+ if ( value == null ) {
117
115
element . removeAttribute ( attribute ) ;
116
+ } else if ( attribute in element && typeof value !== 'string' ) {
117
+ // @ts -ignore
118
+ element [ attribute ] = value ;
118
119
} else {
119
120
element . setAttribute ( attribute , value ) ;
120
121
}
@@ -287,15 +288,15 @@ export function set_attributes(
287
288
name = normalize_attribute ( name ) ;
288
289
}
289
290
290
- if ( setters . includes ( name ) ) {
291
+ if ( setters . includes ( name ) && typeof value !== 'string' ) {
292
+ // @ts -ignore
293
+ element [ name ] = value ;
294
+ } else if ( typeof value !== 'function' ) {
291
295
if ( hydrating && ( name === 'src' || name === 'href' || name === 'srcset' ) ) {
292
- if ( ! skip_warning ) check_src_in_dev_hydration ( element , name , value ) ;
296
+ if ( ! skip_warning ) check_src_in_dev_hydration ( element , name , value ?? '' ) ;
293
297
} else {
294
- // @ts -ignore
295
- element [ name ] = value ;
298
+ set_attribute ( element , name , value ) ;
296
299
}
297
- } else if ( typeof value !== 'function' ) {
298
- set_attribute ( element , name , value ) ;
299
300
}
300
301
}
301
302
}
@@ -350,16 +351,6 @@ export function set_dynamic_element_attributes(node, prev, next, css_hash) {
350
351
) ;
351
352
}
352
353
353
- /**
354
- * List of attributes that should always be set through the attr method,
355
- * because updating them through the property setter doesn't work reliably.
356
- * In the example of `width`/`height`, the problem is that the setter only
357
- * accepts numeric values, but the attribute can also be set to a string like `50%`.
358
- * In case of draggable trying to set `element.draggable='false'` will actually set
359
- * draggable to `true`. If this list becomes too big, rethink this approach.
360
- */
361
- var always_set_through_set_attribute = [ 'width' , 'height' , 'draggable' ] ;
362
-
363
354
/** @type {Map<string, string[]> } */
364
355
var setters_cache = new Map ( ) ;
365
356
@@ -375,7 +366,7 @@ function get_setters(element) {
375
366
descriptors = get_descriptors ( proto ) ;
376
367
377
368
for ( var key in descriptors ) {
378
- if ( descriptors [ key ] . set && ! always_set_through_set_attribute . includes ( key ) ) {
369
+ if ( descriptors [ key ] . set ) {
379
370
setters . push ( key ) ;
380
371
}
381
372
}
@@ -389,12 +380,12 @@ function get_setters(element) {
389
380
/**
390
381
* @param {any } element
391
382
* @param {string } attribute
392
- * @param {string | null } value
383
+ * @param {string } value
393
384
*/
394
385
function check_src_in_dev_hydration ( element , attribute , value ) {
395
386
if ( ! DEV ) return ;
396
387
if ( attribute === 'srcset' && srcset_url_equal ( element , value ) ) return ;
397
- if ( src_url_equal ( element . getAttribute ( attribute ) ?? '' , value ?? '' ) ) return ;
388
+ if ( src_url_equal ( element . getAttribute ( attribute ) ?? '' , value ) ) return ;
398
389
399
390
w . hydration_attribute_changed (
400
391
attribute ,
@@ -420,12 +411,12 @@ function split_srcset(srcset) {
420
411
421
412
/**
422
413
* @param {HTMLSourceElement | HTMLImageElement } element
423
- * @param {string | undefined | null } srcset
414
+ * @param {string } srcset
424
415
* @returns {boolean }
425
416
*/
426
417
function srcset_url_equal ( element , srcset ) {
427
418
var element_urls = split_srcset ( element . srcset ) ;
428
- var urls = split_srcset ( srcset ?? '' ) ;
419
+ var urls = split_srcset ( srcset ) ;
429
420
430
421
return (
431
422
urls . length === element_urls . length &&
0 commit comments