Skip to content

Commit b58bb16

Browse files
authored
fix(runtime-core): should call chained mixins and extends (#3040)
fix #3038
1 parent 86ceef4 commit b58bb16

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

packages/runtime-core/__tests__/apiOptions.spec.ts

+87
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,93 @@ describe('api: options', () => {
644644
expect(renderToString(h(Comp))).toBe('from mixin')
645645
})
646646

647+
test('chained mixins in extends', () => {
648+
const calls: string[] = []
649+
const mixinA = {
650+
beforeCreate() {
651+
calls.push('mixinA beforeCreate')
652+
},
653+
created() {
654+
calls.push('mixinA created')
655+
}
656+
}
657+
658+
const extendA = {
659+
mixins: [mixinA],
660+
beforeCreate() {
661+
calls.push('extendA beforeCreate')
662+
},
663+
created() {
664+
calls.push('extendA created')
665+
}
666+
}
667+
668+
const Comp = {
669+
extends: extendA,
670+
render: () => '123',
671+
beforeCreate() {
672+
calls.push('self beforeCreate')
673+
},
674+
created() {
675+
calls.push('self created')
676+
}
677+
}
678+
679+
expect(renderToString(h(Comp))).toBe(`123`)
680+
expect(calls).toEqual([
681+
'mixinA beforeCreate',
682+
'extendA beforeCreate',
683+
'self beforeCreate',
684+
'mixinA created',
685+
'extendA created',
686+
'self created'
687+
])
688+
})
689+
690+
test('chained extends in mixins', () => {
691+
const calls: string[] = []
692+
693+
const extendA = {
694+
beforeCreate() {
695+
calls.push('extendA beforeCreate')
696+
},
697+
created() {
698+
calls.push('extendA created')
699+
}
700+
}
701+
702+
const mixinA = {
703+
extends: extendA,
704+
beforeCreate() {
705+
calls.push('mixinA beforeCreate')
706+
},
707+
created() {
708+
calls.push('mixinA created')
709+
}
710+
}
711+
712+
const Comp = {
713+
mixins: [mixinA],
714+
render: () => '123',
715+
beforeCreate() {
716+
calls.push('self beforeCreate')
717+
},
718+
created() {
719+
calls.push('self created')
720+
}
721+
}
722+
723+
expect(renderToString(h(Comp))).toBe(`123`)
724+
expect(calls).toEqual([
725+
'extendA beforeCreate',
726+
'mixinA beforeCreate',
727+
'self beforeCreate',
728+
'extendA created',
729+
'mixinA created',
730+
'self created'
731+
])
732+
})
733+
647734
test('extends', () => {
648735
const calls: string[] = []
649736
const Base = {

packages/runtime-core/src/componentOptions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,10 @@ function callHookFromExtends(
839839
if (base.extends) {
840840
callHookFromExtends(name, type, base.extends, instance)
841841
}
842+
const chainedMixins = base.mixins
843+
if (chainedMixins) {
844+
callHookFromMixins(name, type, chainedMixins, instance)
845+
}
842846
const baseHook = base[name]
843847
if (baseHook) {
844848
callWithAsyncErrorHandling(baseHook.bind(instance.proxy!), instance, type)
@@ -853,6 +857,10 @@ function callHookFromMixins(
853857
) {
854858
for (let i = 0; i < mixins.length; i++) {
855859
const chainedMixins = mixins[i].mixins
860+
const chainedExtends = mixins[i].extends
861+
if (chainedExtends) {
862+
callHookFromExtends(name, type, chainedExtends, instance)
863+
}
856864
if (chainedMixins) {
857865
callHookFromMixins(name, type, chainedMixins, instance)
858866
}

0 commit comments

Comments
 (0)