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

v-model assigner is cached #923

Closed
jods4 opened this issue Apr 4, 2020 · 4 comments
Closed

v-model assigner is cached #923

jods4 opened this issue Apr 4, 2020 · 4 comments

Comments

@jods4
Copy link
Contributor

jods4 commented Apr 4, 2020

Version

3.0.0-alpha.11

Reproduction link

https://jsfiddle.net/an4cbzd9/4/

Steps to reproduce

This very specific and I know how to work around it but I'm reporting it anyway:
The assigner used by v-model is cached during onBeforeMount and not updated during onUpdate.
If you assign onUpdate:modelValue manually, it won't reflect changes.

Bonus bug: getModelAssigner doesn't expect an array (i.e. more than on listener under the key onUpdate:). It crashes if you register additional listeners.

Easiest fix seems to be not caching assign in onBeforeUpdate and call getModelAssigner in onUpdate. It currently doesn't do much anyway.

What is expected?

When you type in the textbox, an id is logged in console.
This id should change everytime you click on the button.

What is actually happening?

Id stays the same, even after clicking the button.

@yyx990803
Copy link
Member

I don't really understand why you'd write code that is shown in the repro, but that's not how v-model is designed to be used. The vModelText directive is strictly internal and assumes compiler usage only. Note not everything exported on Vue is part of the public API.

@jods4
Copy link
Contributor Author

jods4 commented Apr 4, 2020

Believe it or not, it came naturally while building a reusable component that wraps an <input>.
I believe it doesn't have to be that convoluted, though.

Problem 1, cached assign

For the cached assign problem, I'd like to ask you a question:
Are you supposed to be able to build a v-model from a render function?
Should I be able to do something like that in JS code (sorry not a JSX user here)?

function MyComp(props) {
 return <input v-model='props.model.name' />;
}

If yes, what would the code look like?
I'm pretty sure that code can be written in a way that exposes this issue.
If not, it's an unforunate limitation, isn't it?

Problem 2, multiple listeners

Documentation is very explicit about how v-model works, in particular that onUpdate:modelValue is the event that updates stuff.
Let's say you want to listen to this event to log the changes, like so:
https://jsfiddle.net/gb4q0j7p/4/
It fails with assign is not a function (the multiple listeners problem I mentionned in issue).

@yyx990803
Copy link
Member

Yeah, this does expose a problem that can happen even in compiled usage. Although I still strongly suggest not relying on any of the internals / undocumented exports. They may break without notice in any release.

@yyx990803 yyx990803 reopened this Apr 5, 2020
@jods4
Copy link
Contributor Author

jods4 commented Apr 5, 2020

@yyx990803 what's the recommended way to write a renderer that creates a v-model?

@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants