-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 setter function not working properly when using functions like replace #10279
Comments
It looks like the problem is more similar to #10254. |
is sure does but the problem is instead of using a ref I was using a reactive containing an object when I first encountered this issue. Does that make a difference? |
Essentially there is no difference, Vue's responsive update is only triggered when the corresponding value changes. Whether you use ref or reactive here their values don't change. |
so you advise that we refer to the other issue? |
I just thought it might not be a problem and maybe you could use the program to solve the problem you are having. Similar to this comment. |
I fixed my problem with a workaround solution I managed to implement. |
Sorry, I now think this might be a bug, and even if it's not a bug it's a very misleading feature, and maybe it should be fixed. As can be found in #10301 and this issue, it's easy to produce results that don't match your intuition when using defineModel's set. |
Yes, this is about the same thing, basically. When the model emits the same value to the parent as it did before, then the parent won't re-render, and the child won't receive a fresh model prop, so it won't update. However I think we might be able to improve this, we can trigger the customRef even if the new value that is to be emitted is the same as the current prop value. Will need testing though. I will also close #10301 as it is presenting the same issue as well, just with a simplified example. |
I am not really sure about what's happening behind the scenes but wouldn't adding a wrapper object behind the scenes make the value to be not the same as the reference is updated??? And I was wondering what do you mean by the same value, doesn't the replace function create a new value in this case? And I was wondering if there is an issue that you can assign me so that I can work on this improvement with the necessary guides? |
Here's a demo of the underlying effect, without using a child component and using a writeable computed instead of When you write digits, it works fine. when you start adding letters, it doesn't update anymore. What's going on? Well,
The same happens basically in your original example, or in the shortened example of #10301, just that the always-same value gets emitted to the parent component - which doesn't need to re-render, so the model prop never gets updated, so the child never re-renders .... I think we can make it work by adding some additional logic in defineModel's internal implementation, but I'm not sure right now if we want that implicit "magic" to take place when |
@LinusBorg I don't get what you mean by the same trimmed value? how is it considered the same if the letters are removed? |
After the letters are removed, you always end up with the same value as one input earlier. Look at my example:
so after 1., Vue has no reason to re-render and update the input value again - it's not aware that it has to.
I'd agree with Evan in #10254 that this is expected behavior in a way, as it is how Vue's reactivity works. As mentioned in my previous reply, I see a possibility for some optimization in Contributing would start with properly understanding the cause of the issue and then talk about possible solutions and their implications with us. |
ok then I will read more about the reactivity and what happens behind the scenes so I can contribute. Thanks |
Vue version
3.4.15
Link to minimal reproduction
https://play.vuejs.org/#eNp9Uk1v2zAM/SuELnGxzD70FrgD9tHDBnQbttymHTybdtXJkiBRWYIg/32UHHtB0eViWXyP1CP5juKtc+UuotiIOrReOYKAFN0badTorCc4gsceTtB7O8KKqasFeji8t/xn0NAZLquLWKrLZABpWmsCwXjY4p7gLlUsVqsbaepqepSf4wvh6HRDyDeA7aMKoIyLBNboAzRti44CdGpQFDaJUl8K2L0ebYe6NHH8hf5Oiuk1KaDienW1FBdrQYEF9Woon4I13PoxqxQtF1Ma/RdHigVLsYGMJKzR2v75lGPkI67nePuI7e8X4k9hn2JSfPUY0O9QigWjxg/IyhJ8//1zVrmA3EXUzL4CfsNgdUwaJ9q7aDqWfcHLaj/mLSkzbMP9ntCEuakkNDFPmS8F7ynN8X+t/5N7W97mPGlOPMVnq75moTTZSNg989FsjB95dWvgQ/UKffjJJumwVwYfElJkLVy12DU64s2sTfVQLDnnzS8gsM0oegM5p/TI62+xqKT88Koa1pANmGjcTm40fy9z5l6vG7WeTEoHh+w6mjx3dmOyYTpfcOHpL8fjLVA=
Steps to reproduce
type in the provided input - make sure that you use a combination of digits and letters
What is expected?
the expected behavior is that the input should only accept digits and not anything else by replacing every non-numeric character with an empty string
What is actually happening?
the problem is that once a single letter is typed the input keeps showing the letters that are being typed until another digit is typed that's when the non-numeric characters are replaced with empty strings
System Info
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: