Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CasualSuperman opened this issue Feb 17, 2024 · 3 comments
Labels
need documentation Not necessarily a bug, but proper documentation is needed scope: defineModel

Comments

@CasualSuperman
Copy link

CasualSuperman commented Feb 17, 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

@sqal
Copy link
Contributor

sqal commented Feb 17, 2024

Some context here vuejs/rfcs#503 (reply in thread)

@LinusBorg
Copy link
Member

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.

@jack-allocate
Copy link

How can we get around this functionality when we cant directly use v-model?

Example (not the author of this reddit post): https://www.reddit.com/r/vuejs/comments/1clppby/tsx_error_when_registering_event_listener_for_an.

I'm having the same issue where I'm using Cypress component testing, but the emitted function provided by @vue/test-utils isn't catching the emitted value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need documentation Not necessarily a bug, but proper documentation is needed scope: defineModel
Projects
None yet
Development

No branches or pull requests

6 participants