File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-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,44 @@ describe('component: emit', () => {
598599 render ( h ( ComponentC ) , el )
599600 expect ( renderFn ) . toHaveBeenCalledTimes ( 1 )
600601 } )
602+ test ( 'merging emits for a component that is also used as a mixin' , ( ) => {
603+ const render = ( ) => h ( 'div' )
604+ const CompA = {
605+ render,
606+ }
607+ const validateByMixin = vi . fn ( ( ) => true )
608+ const validateByGlobalMixin = vi . fn ( ( ) => true )
609+
610+ const mixin = {
611+ emits : {
612+ one : validateByMixin ,
613+ } ,
614+ }
615+
616+ const CompB = defineComponent ( {
617+ mixins : [ mixin , CompA ] ,
618+ created ( this ) {
619+ this . $emit ( 'one' , 1 )
620+ } ,
621+ render,
622+ } )
623+
624+ const app = createApp ( {
625+ render ( ) {
626+ return [ h ( CompA ) , h ( CompB ) ]
627+ } ,
628+ } )
629+
630+ app . mixin ( {
631+ emits : {
632+ one : validateByGlobalMixin ,
633+ two : null ,
634+ } ,
635+ } )
636+
637+ const root = nodeOps . createElement ( 'div' )
638+ app . mount ( root )
639+ expect ( validateByMixin ) . toHaveBeenCalledTimes ( 1 )
640+ expect ( validateByGlobalMixin ) . not . toHaveBeenCalled ( )
641+ } )
601642} )
Original file line number Diff line number Diff line change @@ -228,12 +228,14 @@ export function emit(
228228 }
229229}
230230
231+ const mixinEmitsCache = new WeakMap < ConcreteComponent , ObjectEmitsOptions > ( )
231232export function normalizeEmitsOptions (
232233 comp : ConcreteComponent ,
233234 appContext : AppContext ,
234235 asMixin = false ,
235236) : ObjectEmitsOptions | null {
236- const cache = appContext . emitsCache
237+ const cache =
238+ __FEATURE_OPTIONS_API__ && asMixin ? mixinEmitsCache : appContext . emitsCache
237239 const cached = cache . get ( comp )
238240 if ( cached !== undefined ) {
239241 return cached
You can’t perform that action at this time.
0 commit comments