Unexpected behaviour when making prop (ref) object reactive
Vue version
3.2.47
Link to minimal reproduction
Steps to reproduce
- Create ref with object deep at least 2 levels
- pass it through props to child component
- create local, reactive variable in child component using object descructuring
- make some changes to local object
What is expected?
Changing local variable should not change prop (parent component's) variable
What is actually happening?
Changing local variable also introduces change of original variable from parent component
System Info
No response
Any additional comments?
No response
This appears to be working correctly to me.
msg.value
and props.updateFileData
are the same object. This is creating a shallow copy of that object:
const formData = reactive({
...props.updateFileData
});
So formData
is a different object. But the nested object in msg.value.test
and props.updateFileData.test
is the same object as formData.test
. Try adding {{ updateFileData.test === formData.test }}
to your template, it should confirm that they are the same object.
If you have further questions about this I suggest asking on the Vue Discord at https://chat.vuejs.org/.