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', () => {
14891489 mountWithHydration ( `<div id="bar"></div>` , ( ) => h ( 'div' , { id : 'foo' } ) )
14901490 expect ( `Hydration attribute mismatch` ) . toHaveBeenWarnedTimes ( 2 )
14911491 } )
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+ } )
14921507 } )
14931508} )
Original file line number Diff line number Diff line change @@ -754,19 +754,18 @@ function propHasMismatch(
754754 ( el instanceof SVGElement && isKnownSvgAttr ( key ) ) ||
755755 ( el instanceof HTMLElement && ( isBooleanAttr ( key ) || isKnownHtmlAttr ( key ) ) )
756756 ) {
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+ }
770769 if ( actual !== expected ) {
771770 mismatchType = `attribute`
772771 mismatchKey = key
You can’t perform that action at this time.
0 commit comments