Subscribe on changes!

defineModel value de-synchronizes between parent and child if @update handler is not provided

avatar
Feb 17th 2024

Vue version

3.4.15

Link to minimal reproduction

https://play.vuejs.org/#eNqlVUlP20AU/itT9wBI2FZFL01NRFkOrdQWAerJl4nnxRmYTbMEUJT/3jfjJNghLBI3z1u/721eZD+MKeYBslFWucZy44kDH8y4VlwabT1ZEAtTsiRTqyXZQ9O97xvdmZZmpSjK+Iihor5WjVbOoytlWonHS6sNOY6R9r0NcIAmQ4PfmoHYsqjKDhFiwYcHaQT1gC9CKmeoGl9SC8oTLbn3XLXExCwo4RbEI3pHm2Q9saTsvhLi1fckeK8VYdzRiQA2vtFtK4B0UauyUw8CPEuNGeecxdyRRAdgTkUAUoEkzj8KOK6zRgttRxZYnY33T0NLriCV77oBRS3XB1UJcvwKYPTtyoTB+iWtsy0uJ43gzd2WFZb109DrY1R7LKliJBiGbSEz/BZgX2Exz2Xs8i4yqf1vs1lPyYbOyu8dfKqyN0DZYdZNcC6pKW6dVjj/i2herxSuzkYkSaIMpzq+62zmvXGjsmyYQjfMzee2UOBLZWR5gmalDTh/EnKm5clR8bX48q3EAfN9eQFO5hOr7x1YjFJnh708JQrnYHMkwsCCfW/eLbdB7i3ds/wx/bJWSyyLd7iXU95uFaXB/nHs7l/jOe7toDhUCH3/K8ni5m7INDNo7nbIb91DR+rSQkLWK4CntgXfqS+u/8ADfm+UOD1BrBrxgvIKnBYhYuzMTkMayp5dQvsz9Rhn+cZdPHhQbk0qAk3VSPapIXF0X6L+BPeoOOpVcX0Kd1zV4dnDWWYw5QrSIO8/TToiJgtU0SB8B2v51knkygS/81SkxSL/4sYi+MVavES0gy19ae36G/e0bGczLlhv1wYbhs90/eJ/JOJKsPIULFVvQpu71mpsT95dR/L5/PwcGSImJJlcs+V/MAJIzg==

Steps to reproduce

Provide a prop value but no @update handler for a v-model prop on a child component using defineModel.

To reproduce in the example, click the middle "Toggle Child" button.

What is expected?

Props are not typically considered writable, and defineModel emulates a prop/$emit pair, so writes to the value should not have a (direct) effect. Since the parent component has provided a value, that value is the one that should be used. This demonstrates what I think is the expected behavior, since this is how v-models are documented to work under the hood. Omitting the update event handler should tell the child component that the parent does not care if the child wants to update the value, and the event/update should be ignored.

What is actually happening?

After initialization, the value behaves like a local ref, and ignores the value provided by the parent, unless it changes.

System Info

System:
    OS: Linux 6.6 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Memory: 2.11 GB / 30.98 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node
    Yarn: 4.1.0 - /usr/bin/yarn
    npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm
    pnpm: 8.6.0 - /usr/bin/pnpm
  npmPackages:
    vue: ^3.4.15 => 3.4.15 


### Any additional comments?

_No response_
avatar
Feb 20th 2024

This is actually designed this way, but missing in the docs. We'll make sure to amend the docs accordingly. I'll leave this open until we have done that.