@@ -38,26 +38,30 @@ export function attr_effect(dom, attribute, value) {
38
38
export function attr ( dom , attribute , value ) {
39
39
value = value == null ? null : value + '' ;
40
40
41
+ var attributes = ( dom . __attributes ??= { } ) ;
42
+
43
+ if ( hydrating ) {
44
+ attributes [ attribute ] = dom . getAttribute ( attribute ) ;
45
+ }
46
+
47
+ if ( attributes [ attribute ] === ( attributes [ attribute ] = value ) ) return ;
48
+
41
49
if ( DEV ) {
42
50
check_src_in_dev_hydration ( dom , attribute , value ) ;
43
51
}
44
52
45
- if (
46
- ! hydrating ||
47
- ( dom . getAttribute ( attribute ) !== value &&
48
- // If we reset those, they would result in another network request, which we want to avoid.
49
- // We assume they are the same between client and server as checking if they are equal is expensive
50
- // (we can't just compare the strings as they can be different between client and server but result in the
51
- // same url, so we would need to create hidden anchor elements to compare them)
52
- attribute !== 'src' &&
53
- attribute !== 'href' &&
54
- attribute !== 'srcset' )
55
- ) {
56
- if ( value === null ) {
57
- dom . removeAttribute ( attribute ) ;
58
- } else {
59
- dom . setAttribute ( attribute , value ) ;
60
- }
53
+ if ( hydrating && ( attribute === 'src' || attribute === 'href' || attribute === 'srcset' ) ) {
54
+ // If we reset these attributes, they would result in another network request, which we want to avoid.
55
+ // We assume they are the same between client and server as checking if they are equal is expensive
56
+ // (we can't just compare the strings as they can be different between client and server but result in the
57
+ // same url, so we would need to create hidden anchor elements to compare them)
58
+ return ;
59
+ }
60
+
61
+ if ( value === null ) {
62
+ dom . removeAttribute ( attribute ) ;
63
+ } else {
64
+ dom . setAttribute ( attribute , value ) ;
61
65
}
62
66
}
63
67
0 commit comments