Skip to content

Commit

Permalink
fix(runtime-core): dimiss extended component props
Browse files Browse the repository at this point in the history
  • Loading branch information
gcaaa31928 committed Mar 31, 2023
1 parent a94072d commit 4d69d20
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`<div>ExtendedComp from global </div><div>Comp from global </div>`
)
expect(renderProxy.$props).toMatchObject({ globalProp: defaultProp })
expect(extendedRenderProxy.$props).toMatchObject({
globalProp: defaultProp
})
})

test('merging props from global mixins', () => {
let setupProps: any
let renderProxy: any
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function normalizePropsOptions(
}
}

if (!raw && !hasExtends) {
if (!raw && !hasExtends && !asMixin) {
if (isObject(comp)) {
cache.set(comp, EMPTY_ARR as any)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d69d20

Please sign in to comment.