@@ -20,6 +20,9 @@ import { NAMESPACE_HTML } from '../../../../constants.js';
20
20
export const CLASS = Symbol ( 'class' ) ;
21
21
export const STYLE = Symbol ( 'style' ) ;
22
22
23
+ const IS_CUSTOM_ELEMENT = Symbol ( 'is custom element' ) ;
24
+ const IS_HTML = Symbol ( 'is html' ) ;
25
+
23
26
/**
24
27
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
25
28
* to remove it upon hydration to avoid a bug when someone resets the form value.
@@ -64,8 +67,7 @@ export function remove_input_defaults(input) {
64
67
* @param {any } value
65
68
*/
66
69
export function set_value ( element , value ) {
67
- // @ts -expect-error
68
- var attributes = ( element . __attributes ??= { } ) ;
70
+ var attributes = get_attributes ( element ) ;
69
71
70
72
if (
71
73
attributes . value ===
@@ -88,8 +90,7 @@ export function set_value(element, value) {
88
90
* @param {boolean } checked
89
91
*/
90
92
export function set_checked ( element , checked ) {
91
- // @ts -expect-error
92
- var attributes = ( element . __attributes ??= { } ) ;
93
+ var attributes = get_attributes ( element ) ;
93
94
94
95
if (
95
96
attributes . checked ===
@@ -152,8 +153,7 @@ export function set_default_value(element, value) {
152
153
* @param {boolean } [skip_warning]
153
154
*/
154
155
export function set_attribute ( element , attribute , value , skip_warning ) {
155
- // @ts -expect-error
156
- var attributes = ( element . __attributes ??= { } ) ;
156
+ var attributes = get_attributes ( element ) ;
157
157
158
158
if ( hydrating ) {
159
159
attributes [ attribute ] = element . getAttribute ( attribute ) ;
@@ -266,8 +266,10 @@ export function set_custom_element_data(node, prop, value) {
266
266
* @returns {Record<string, any> }
267
267
*/
268
268
export function set_attributes ( element , prev , next , css_hash , skip_warning = false ) {
269
- var is_custom_element = element . nodeName . includes ( '-' ) ;
270
- var preserve_attribute_case = is_custom_element || element . namespaceURI !== NAMESPACE_HTML ;
269
+ var attributes = get_attributes ( element ) ;
270
+
271
+ var is_custom_element = attributes [ IS_CUSTOM_ELEMENT ] ;
272
+ var preserve_attribute_case = ! attributes [ IS_HTML ] ;
271
273
272
274
// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
273
275
// then it might run block logic in hydration mode, which we have to prevent.
@@ -293,9 +295,6 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
293
295
294
296
var setters = get_setters ( element ) ;
295
297
296
- // @ts -expect-error
297
- var attributes = /** @type {Record<string, unknown> } **/ ( element . __attributes ??= { } ) ;
298
-
299
298
// since key is captured we use const
300
299
for ( const key in next ) {
301
300
// let instead of var because referenced in a closure
@@ -442,6 +441,20 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
442
441
return current ;
443
442
}
444
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
+
445
458
/** @type {Map<string, string[]> } */
446
459
var setters_cache = new Map ( ) ;
447
460
0 commit comments