@@ -9,9 +9,9 @@ import { hydrating } from '../hydration.js';
9
9
*/
10
10
export function svelte_html ( get_attributes ) {
11
11
const node = document . documentElement ;
12
- const own = { } ;
12
+ const self = { } ;
13
13
14
- /** @type {Record<string, Array<[ any, any] >> } to check who set the last value of each attribute */
14
+ /** @type {Record<string, Array<{ owner: any, value: any } >> } to check who set the last value of each attribute */
15
15
// @ts -expect-error
16
16
const current_setters = ( node . __attributes_setters ??= { } ) ;
17
17
@@ -23,11 +23,11 @@ export function svelte_html(get_attributes) {
23
23
24
24
for ( const name in attributes ) {
25
25
const current = ( current_setters [ name ] ??= [ ] ) ;
26
- const index = current . findIndex ( ( [ owner ] ) => owner === own ) ;
27
- const old = index === - 1 ? null : current . splice ( index , 1 ) [ 0 ] [ 1 ] ;
26
+ const index = current . findIndex ( ( c ) => c . owner === self ) ;
27
+ const old = index === - 1 ? null : current . splice ( index , 1 ) [ 0 ] . value ;
28
28
29
29
let value = attributes [ name ] ;
30
- current . push ( [ own , value ] ) ;
30
+ current . push ( { owner : self , value } ) ;
31
31
32
32
// Do nothing on initial render during hydration: If there are attribute duplicates, the last value
33
33
// wins, which could result in needless hydration repairs from earlier values.
@@ -36,7 +36,7 @@ export function svelte_html(get_attributes) {
36
36
if ( name === 'class' ) {
37
37
// Avoid unrelated attribute changes from triggering class changes
38
38
if ( old !== value ) {
39
- set_class ( node , current_setters [ name ] . map ( ( [ _ , text ] ) => text ) . join ( ' ' ) ) ;
39
+ set_class ( node , current_setters [ name ] . map ( ( e ) => e . value ) . join ( ' ' ) ) ;
40
40
}
41
41
} else {
42
42
set_attribute ( node , name , value ) ;
@@ -47,15 +47,15 @@ export function svelte_html(get_attributes) {
47
47
teardown ( ( ) => {
48
48
for ( const name in attributes ) {
49
49
const old = current_setters [ name ] ;
50
- current_setters [ name ] = old . filter ( ( [ owner ] ) => owner !== own ) ;
50
+ current_setters [ name ] = old . filter ( ( o ) => o . owner !== self ) ;
51
51
const current = current_setters [ name ] ;
52
52
53
53
if ( name === 'class' ) {
54
- set_class ( node , current . map ( ( [ _ , text ] ) => text ) . join ( ' ' ) ) ;
54
+ set_class ( node , current . map ( ( c ) => c . value ) . join ( ' ' ) ) ;
55
55
56
56
// If this was the last one setting this attribute, revert to the previous value
57
- } else if ( old [ old . length - 1 ] [ 0 ] === own ) {
58
- set_attribute ( node , name , current [ current . length - 1 ] ?. [ 1 ] ) ;
57
+ } else if ( old [ old . length - 1 ] . owner === self ) {
58
+ set_attribute ( node , name , current [ current . length - 1 ] ?. value ) ;
59
59
}
60
60
}
61
61
} ) ;
0 commit comments