Skip to content

Commit 08382f0

Browse files
committed
fix(props): should not unwrap props that are raw refs
close #12930
1 parent 947993f commit 08382f0

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

src/core/instance/state.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,25 @@ function initProps(vm: Component, propsOptions: Object) {
9595
vm
9696
)
9797
}
98-
defineReactive(props, key, value, () => {
99-
if (!isRoot && !isUpdatingChildComponent) {
100-
warn(
101-
`Avoid mutating a prop directly since the value will be ` +
102-
`overwritten whenever the parent component re-renders. ` +
103-
`Instead, use a data or computed property based on the prop's ` +
104-
`value. Prop being mutated: "${key}"`,
105-
vm
106-
)
107-
}
108-
})
98+
defineReactive(
99+
props,
100+
key,
101+
value,
102+
() => {
103+
if (!isRoot && !isUpdatingChildComponent) {
104+
warn(
105+
`Avoid mutating a prop directly since the value will be ` +
106+
`overwritten whenever the parent component re-renders. ` +
107+
`Instead, use a data or computed property based on the prop's ` +
108+
`value. Prop being mutated: "${key}"`,
109+
vm
110+
)
111+
}
112+
},
113+
true
114+
)
109115
} else {
110-
defineReactive(props, key, value)
116+
defineReactive(props, key, value, undefined, true)
111117
}
112118
// static props are already proxied on the component's prototype
113119
// during Vue.extend(). We only need to proxy props defined at

test/unit/features/options/props.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import { hasSymbol } from 'core/util/env'
33
import testObjectOption from '../../../helpers/test-object-option'
4+
import { ref } from 'v3'
45

56
describe('Options props', () => {
67
testObjectOption('props')
@@ -593,4 +594,21 @@ describe('Options props', () => {
593594
'Invalid prop type: "String" is not a constructor'
594595
).toHaveBeenWarned()
595596
})
597+
598+
// #12930
599+
it('should not unwrap prop values that are raw refs', () => {
600+
let val
601+
const Comp = {
602+
props: ['msg'],
603+
created() {
604+
val = this.msg
605+
},
606+
render() {}
607+
}
608+
const r = ref()
609+
new Vue({
610+
render: h => h(Comp, { props: { msg: r }})
611+
}).$mount()
612+
expect(val).toBe(r)
613+
})
596614
})

0 commit comments

Comments
 (0)