diff --git a/packages/runtime-core/__tests__/componentProps.spec.ts b/packages/runtime-core/__tests__/componentProps.spec.ts index 071a24f138d..3e722227c2c 100644 --- a/packages/runtime-core/__tests__/componentProps.spec.ts +++ b/packages/runtime-core/__tests__/componentProps.spec.ts @@ -442,6 +442,54 @@ describe('component props', () => { expect(renderProxy.$props).toMatchObject(props) }) + test('merging props from global mixins and extend, and extended component should not have props cache', () => { + let renderProxy: any + let extendedRenderProxy: any + + const defaultProp = ' from global ' + const props = { + globalProp: { + type: String, + default: defaultProp + } + } + const globalMixin = { + props + } + const Comp = { + render(this: any) { + renderProxy = this + return h('div', ['Comp', this.globalProp]) + } + } + const ExtendedComp = { + extends: Comp, + render(this: any) { + extendedRenderProxy = this + return h('div', ['ExtendedComp', this.globalProp]) + } + } + + const app = createApp( + { + render: () => [h(ExtendedComp), h(Comp)] + }, + {} + ) + app.mixin(globalMixin) + + const root = nodeOps.createElement('div') + app.mount(root) + + expect(serializeInner(root)).toMatch( + `
ExtendedComp from global
Comp from global
` + ) + expect(renderProxy.$props).toMatchObject({ globalProp: defaultProp }) + expect(extendedRenderProxy.$props).toMatchObject({ + globalProp: defaultProp + }) + }) + test('merging props from global mixins', () => { let setupProps: any let renderProxy: any diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 03c83990c57..2564187a0cd 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -497,7 +497,7 @@ export function normalizePropsOptions( } } - if (!raw && !hasExtends) { + if (!raw && !hasExtends && !asMixin) { if (isObject(comp)) { cache.set(comp, EMPTY_ARR as any) } @@ -540,7 +540,7 @@ export function normalizePropsOptions( } const res: NormalizedPropsOptions = [normalized, needCastKeys] - if (isObject(comp)) { + if (isObject(comp) && !asMixin) { cache.set(comp, res) } return res