File tree Expand file tree Collapse file tree 2 files changed +27
-13
lines changed Expand file tree Collapse file tree 2 files changed +27
-13
lines changed Original file line number Diff line number Diff line change @@ -1489,5 +1489,20 @@ describe('SSR hydration', () => {
1489
1489
mountWithHydration ( `<div id="bar"></div>` , ( ) => h ( 'div' , { id : 'foo' } ) )
1490
1490
expect ( `Hydration attribute mismatch` ) . toHaveBeenWarnedTimes ( 2 )
1491
1491
} )
1492
+
1493
+ test ( 'boolean attr handling' , ( ) => {
1494
+ mountWithHydration ( `<input />` , ( ) => h ( 'input' , { readonly : false } ) )
1495
+ expect ( `Hydration attribute mismatch` ) . not . toHaveBeenWarned ( )
1496
+
1497
+ mountWithHydration ( `<input readonly />` , ( ) =>
1498
+ h ( 'input' , { readonly : true } ) ,
1499
+ )
1500
+ expect ( `Hydration attribute mismatch` ) . not . toHaveBeenWarned ( )
1501
+
1502
+ mountWithHydration ( `<input readonly="readonly" />` , ( ) =>
1503
+ h ( 'input' , { readonly : true } ) ,
1504
+ )
1505
+ expect ( `Hydration attribute mismatch` ) . not . toHaveBeenWarned ( )
1506
+ } )
1492
1507
} )
1493
1508
} )
Original file line number Diff line number Diff line change @@ -754,19 +754,18 @@ function propHasMismatch(
754
754
( el instanceof SVGElement && isKnownSvgAttr ( key ) ) ||
755
755
( el instanceof HTMLElement && ( isBooleanAttr ( key ) || isKnownHtmlAttr ( key ) ) )
756
756
) {
757
- // #10000 some attrs such as textarea.value can't be get by `hasAttribute`
758
- actual = el . hasAttribute ( key )
759
- ? el . getAttribute ( key )
760
- : key in el
761
- ? el [ key as keyof typeof el ]
762
- : ''
763
- expected = isBooleanAttr ( key )
764
- ? includeBooleanAttr ( clientValue )
765
- ? ''
766
- : false
767
- : clientValue == null
768
- ? ''
769
- : String ( clientValue )
757
+ if ( isBooleanAttr ( key ) ) {
758
+ actual = el . hasAttribute ( key )
759
+ expected = includeBooleanAttr ( clientValue )
760
+ } else {
761
+ // #10000 some attrs such as textarea.value can't be get by `hasAttribute`
762
+ actual = el . hasAttribute ( key )
763
+ ? el . getAttribute ( key )
764
+ : key in el
765
+ ? el [ key as keyof typeof el ]
766
+ : ''
767
+ expected = clientValue == null ? '' : String ( clientValue )
768
+ }
770
769
if ( actual !== expected ) {
771
770
mismatchType = `attribute`
772
771
mismatchKey = key
You can’t perform that action at this time.
0 commit comments