File tree 2 files changed +45
-2
lines changed
2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ import {
11
11
createBlock ,
12
12
FunctionalComponent ,
13
13
createCommentVNode ,
14
- Fragment
14
+ Fragment ,
15
+ withModifiers
15
16
} from '@vue/runtime-dom'
16
17
import { PatchFlags } from '@vue/shared/src'
17
18
@@ -383,6 +384,45 @@ describe('attribute fallthrough', () => {
383
384
expect ( `Extraneous non-emits event listeners` ) . toHaveBeenWarned ( )
384
385
} )
385
386
387
+ it ( 'should dedupe same listeners when $attrs is used during render' , ( ) => {
388
+ const click = jest . fn ( )
389
+ const count = ref ( 0 )
390
+
391
+ function inc ( ) {
392
+ count . value ++
393
+ click ( )
394
+ }
395
+
396
+ const Parent = {
397
+ render ( ) {
398
+ return h ( Child , { onClick : inc } )
399
+ }
400
+ }
401
+
402
+ const Child = defineComponent ( {
403
+ render ( ) {
404
+ return h (
405
+ 'div' ,
406
+ mergeProps (
407
+ {
408
+ onClick : withModifiers ( ( ) => { } , [ 'prevent' , 'stop' ] )
409
+ } ,
410
+ this . $attrs
411
+ )
412
+ )
413
+ }
414
+ } )
415
+
416
+ const root = document . createElement ( 'div' )
417
+ document . body . appendChild ( root )
418
+ render ( h ( Parent ) , root )
419
+
420
+ const node = root . children [ 0 ] as HTMLElement
421
+ node . dispatchEvent ( new CustomEvent ( 'click' ) )
422
+ expect ( click ) . toHaveBeenCalledTimes ( 1 )
423
+ expect ( count . value ) . toBe ( 1 )
424
+ } )
425
+
386
426
it ( 'should not warn when $attrs is used during render' , ( ) => {
387
427
const Parent = {
388
428
render ( ) {
Original file line number Diff line number Diff line change @@ -791,7 +791,10 @@ export function mergeProps(...args: (Data & VNodeProps)[]) {
791
791
} else if ( isOn ( key ) ) {
792
792
const existing = ret [ key ]
793
793
const incoming = toMerge [ key ]
794
- if ( existing !== incoming ) {
794
+ if (
795
+ existing !== incoming &&
796
+ ! ( isArray ( existing ) && existing . includes ( incoming ) )
797
+ ) {
795
798
ret [ key ] = existing
796
799
? [ ] . concat ( existing as any , incoming as any )
797
800
: incoming
You can’t perform that action at this time.
0 commit comments