File tree 2 files changed +44
-2
lines changed
2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -612,4 +612,44 @@ describe('useModel', () => {
612
612
// should not force local update if set to the same value
613
613
expect ( compRender ) . toHaveBeenCalledTimes ( 3 )
614
614
} )
615
+
616
+ test ( 'set no change value' , async ( ) => {
617
+ let changeChildMsg : ( ( ) => void ) | null = null
618
+
619
+ const compRender = vi . fn ( )
620
+ const Comp = defineComponent ( {
621
+ props : [ 'msg' ] ,
622
+ emits : [ 'update:msg' ] ,
623
+ setup ( props ) {
624
+ const childMsg = useModel ( props , 'msg' )
625
+ changeChildMsg = ( ) => {
626
+ childMsg . value = childMsg . value
627
+ }
628
+ return ( ) => {
629
+ return childMsg . value
630
+ }
631
+ } ,
632
+ } )
633
+
634
+ const msg = ref ( 'HI' )
635
+ const Parent = defineComponent ( {
636
+ setup ( ) {
637
+ return ( ) =>
638
+ h ( Comp , {
639
+ msg : msg . value ,
640
+ 'onUpdate:msg' : val => {
641
+ msg . value = val
642
+ compRender ( )
643
+ } ,
644
+ } )
645
+ } ,
646
+ } )
647
+
648
+ const root = nodeOps . createElement ( 'div' )
649
+ render ( h ( Parent ) , root )
650
+
651
+ expect ( compRender ) . toBeCalledTimes ( 0 )
652
+ changeChildMsg ! ( )
653
+ expect ( compRender ) . toBeCalledTimes ( 0 )
654
+ } )
615
655
} )
Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ export function useModel(
51
51
} ,
52
52
53
53
set ( value ) {
54
+ if ( ! hasChanged ( value , localValue ) ) {
55
+ return
56
+ }
54
57
const rawProps = i . vnode ! . props
55
58
if (
56
59
! (
@@ -62,8 +65,7 @@ export function useModel(
62
65
( `onUpdate:${ name } ` in rawProps ||
63
66
`onUpdate:${ camelizedName } ` in rawProps ||
64
67
`onUpdate:${ hyphenatedName } ` in rawProps )
65
- ) &&
66
- hasChanged ( value , localValue )
68
+ )
67
69
) {
68
70
// no v-model, local update
69
71
localValue = value
You can’t perform that action at this time.
0 commit comments