@@ -15,10 +15,14 @@ import {
15
15
} from '../../runtime.js' ;
16
16
import { clsx } from '../../../shared/attributes.js' ;
17
17
import { set_class } from './class.js' ;
18
+ import { NAMESPACE_HTML } from '../../../../constants.js' ;
18
19
19
20
export const CLASS = Symbol ( 'class' ) ;
20
21
export const STYLE = Symbol ( 'style' ) ;
21
22
23
+ const IS_CUSTOM_ELEMENT = Symbol ( 'is custom element' ) ;
24
+ const IS_HTML = Symbol ( 'is html' ) ;
25
+
22
26
/**
23
27
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
24
28
* to remove it upon hydration to avoid a bug when someone resets the form value.
@@ -63,8 +67,7 @@ export function remove_input_defaults(input) {
63
67
* @param {any } value
64
68
*/
65
69
export function set_value ( element , value ) {
66
- // @ts -expect-error
67
- var attributes = ( element . __attributes ??= { } ) ;
70
+ var attributes = get_attributes ( element ) ;
68
71
69
72
if (
70
73
attributes . value ===
@@ -87,8 +90,7 @@ export function set_value(element, value) {
87
90
* @param {boolean } checked
88
91
*/
89
92
export function set_checked ( element , checked ) {
90
- // @ts -expect-error
91
- var attributes = ( element . __attributes ??= { } ) ;
93
+ var attributes = get_attributes ( element ) ;
92
94
93
95
if (
94
96
attributes . checked ===
@@ -151,8 +153,7 @@ export function set_default_value(element, value) {
151
153
* @param {boolean } [skip_warning]
152
154
*/
153
155
export function set_attribute ( element , attribute , value , skip_warning ) {
154
- // @ts -expect-error
155
- var attributes = ( element . __attributes ??= { } ) ;
156
+ var attributes = get_attributes ( element ) ;
156
157
157
158
if ( hydrating ) {
158
159
attributes [ attribute ] = element . getAttribute ( attribute ) ;
@@ -261,20 +262,15 @@ export function set_custom_element_data(node, prop, value) {
261
262
* @param {Record<string | symbol, any> | undefined } prev
262
263
* @param {Record<string | symbol, any> } next New attributes - this function mutates this object
263
264
* @param {string } [css_hash]
264
- * @param {boolean } [preserve_attribute_case]
265
- * @param {boolean } [is_custom_element]
266
265
* @param {boolean } [skip_warning]
267
266
* @returns {Record<string, any> }
268
267
*/
269
- export function set_attributes (
270
- element ,
271
- prev ,
272
- next ,
273
- css_hash ,
274
- preserve_attribute_case = false ,
275
- is_custom_element = false ,
276
- skip_warning = false
277
- ) {
268
+ export function set_attributes ( element , prev , next , css_hash , skip_warning = false ) {
269
+ var attributes = get_attributes ( element ) ;
270
+
271
+ var is_custom_element = attributes [ IS_CUSTOM_ELEMENT ] ;
272
+ var preserve_attribute_case = ! attributes [ IS_HTML ] ;
273
+
278
274
// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
279
275
// then it might run block logic in hydration mode, which we have to prevent.
280
276
let is_hydrating_custom_element = hydrating && is_custom_element ;
@@ -299,9 +295,6 @@ export function set_attributes(
299
295
300
296
var setters = get_setters ( element ) ;
301
297
302
- // @ts -expect-error
303
- var attributes = /** @type {Record<string, unknown> } **/ ( element . __attributes ??= { } ) ;
304
-
305
298
// since key is captured we use const
306
299
for ( const key in next ) {
307
300
// let instead of var because referenced in a closure
@@ -432,7 +425,7 @@ export function set_attributes(
432
425
// @ts -ignore
433
426
element [ name ] = value ;
434
427
} else if ( typeof value !== 'function' ) {
435
- set_attribute ( element , name , value ) ;
428
+ set_attribute ( element , name , value , skip_warning ) ;
436
429
}
437
430
}
438
431
if ( key === 'style' && '__styles' in element ) {
@@ -448,6 +441,20 @@ export function set_attributes(
448
441
return current ;
449
442
}
450
443
444
+ /**
445
+ *
446
+ * @param {Element } element
447
+ */
448
+ function get_attributes ( element ) {
449
+ return /** @type {Record<string | symbol, unknown> } **/ (
450
+ // @ts -expect-error
451
+ element . __attributes ??= {
452
+ [ IS_CUSTOM_ELEMENT ] : element . nodeName . includes ( '-' ) ,
453
+ [ IS_HTML ] : element . namespaceURI === NAMESPACE_HTML
454
+ }
455
+ ) ;
456
+ }
457
+
451
458
/** @type {Map<string, string[]> } */
452
459
var setters_cache = new Map ( ) ;
453
460
0 commit comments