File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 33
44import {
55 type ComponentPublicInstance ,
6+ createApp ,
67 defineComponent ,
78 h ,
89 nextTick ,
@@ -598,4 +599,45 @@ describe('component: emit', () => {
598599 render ( h ( ComponentC ) , el )
599600 expect ( renderFn ) . toHaveBeenCalledTimes ( 1 )
600601 } )
602+
603+ test ( 'merging emits for a component that is also used as a mixin' , ( ) => {
604+ const render = ( ) => h ( 'div' )
605+ const CompA = {
606+ render,
607+ }
608+ const validateByMixin = vi . fn ( ( ) => true )
609+ const validateByGlobalMixin = vi . fn ( ( ) => true )
610+
611+ const mixin = {
612+ emits : {
613+ one : validateByMixin ,
614+ } ,
615+ }
616+
617+ const CompB = defineComponent ( {
618+ mixins : [ mixin , CompA ] ,
619+ created ( this ) {
620+ this . $emit ( 'one' , 1 )
621+ } ,
622+ render,
623+ } )
624+
625+ const app = createApp ( {
626+ render ( ) {
627+ return [ h ( CompA ) , h ( CompB ) ]
628+ } ,
629+ } )
630+
631+ app . mixin ( {
632+ emits : {
633+ one : validateByGlobalMixin ,
634+ two : null ,
635+ } ,
636+ } )
637+
638+ const root = nodeOps . createElement ( 'div' )
639+ app . mount ( root )
640+ expect ( validateByMixin ) . toHaveBeenCalledTimes ( 1 )
641+ expect ( validateByGlobalMixin ) . not . toHaveBeenCalled ( )
642+ } )
601643} )
Original file line number Diff line number Diff line change @@ -232,12 +232,14 @@ export function emit(
232232 }
233233}
234234
235+ const mixinEmitsCache = new WeakMap < ConcreteComponent , ObjectEmitsOptions > ( )
235236export function normalizeEmitsOptions (
236237 comp : ConcreteComponent ,
237238 appContext : AppContext ,
238239 asMixin = false ,
239240) : ObjectEmitsOptions | null {
240- const cache = appContext . emitsCache
241+ const cache =
242+ __FEATURE_OPTIONS_API__ && asMixin ? mixinEmitsCache : appContext . emitsCache
241243 const cached = cache . get ( comp )
242244 if ( cached !== undefined ) {
243245 return cached
You can’t perform that action at this time.
0 commit comments