fix(runtime-core): avoid double-setting props when casting
fix #3371, close #3384
This commit is contained in:
@@ -12,7 +12,8 @@ import {
|
||||
provide,
|
||||
inject,
|
||||
watch,
|
||||
toRefs
|
||||
toRefs,
|
||||
SetupContext
|
||||
} from '@vue/runtime-test'
|
||||
import { render as domRender, nextTick } from 'vue'
|
||||
|
||||
@@ -508,4 +509,51 @@ describe('component props', () => {
|
||||
await nextTick()
|
||||
expect(changeSpy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
// #3371
|
||||
test(`avoid double-setting props when casting`, async () => {
|
||||
const Parent = {
|
||||
setup(props: any, { slots }: SetupContext) {
|
||||
const childProps = ref()
|
||||
const registerChildProps = (props: any) => {
|
||||
childProps.value = props
|
||||
}
|
||||
provide('register', registerChildProps)
|
||||
|
||||
return () => {
|
||||
// access the child component's props
|
||||
childProps.value && childProps.value.foo
|
||||
return slots.default!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Child = {
|
||||
props: {
|
||||
foo: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
setup(props: { foo: boolean }) {
|
||||
const register = inject('register') as any
|
||||
// 1. change the reactivity data of the parent component
|
||||
// 2. register its own props to the parent component
|
||||
register(props)
|
||||
|
||||
return () => 'foo'
|
||||
}
|
||||
}
|
||||
|
||||
const App = {
|
||||
setup() {
|
||||
return () => h(Parent, () => h(Child as any, { foo: '' }, () => null))
|
||||
}
|
||||
}
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(App), root)
|
||||
await nextTick()
|
||||
expect(serializeInner(root)).toBe(`foo`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user