core icon indicating copy to clipboard operation
core copied to clipboard

defineModel behavior without parent passing v-model different between strings and arrays

Open danielkellyio opened this issue 1 year ago • 4 comments

Vue version

3.4.38

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-9pbycg?file=src%2FApp.vue,src%2Fcomponents%2FMyArrayComponent.vue,src%2Fcomponents%2FMyStringComponent.vue&terminal=dev

Steps to reproduce

  1. use defineModel in a child component to define some array data (call it model)
  2. alter model by pushing a new array item to it

What is expected?

Template to re-render with new item in the array

What is actually happening?

template does not re-render

System Info

No response

Any additional comments?

Replacing the entire array works as expected but pushing does not. Maybe this is intended (not deep)? If so, perhaps the docs should include a note about this.

Thanks!

danielkellyio avatar Aug 26 '24 21:08 danielkellyio

This is the intended behavior. The model is a custom ref and only triggers when .value is replaced.

edison1105 avatar Aug 27 '24 00:08 edison1105

I don't understand where the "intended behavior" is defined, as the original RFC didn't mention the limitation that only primitives would be supported. This feels more like a bug to me; if defineModel creates a ref why shouldn't it behave like a standard ref? And why would the behavior be different when v-model is provided vs not provided?

dabernathy89 avatar Nov 04 '24 16:11 dabernathy89

I'm having the same problem here and i also don't get why it should be intended behavior, it would be much more intuitive, if it would work also with not primitive types. Because the way it is now it's just an easy way to include bugs.

SebastianStolze avatar Feb 11 '25 13:02 SebastianStolze

I have the same problem. Will any work be done on this issue? Something like { default: () => [], deep: true }

b01010110 avatar Nov 03 '25 15:11 b01010110