-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Description
Vue version
3.5.17
Link to minimal reproduction
Steps to reproduce
- Create a component that uses
defineModel
to set up 2 way binding - Within that component, alter the model and then read its value after within the same tick on some action (
onBeforeMount
, on a button click, etc.) - Import and use the component both with the 2-way binding connected and without it fully connected
- Observe the value read from the model is sometimes the pre-update value, and in other cases is the post-update value
What is expected?
The model is updated with consistent timing regardless if props are provided or events handlers are provided. I think ideally the model would be updated within the same tick so that reading from it afterwards is intuitive.
Ex:
const model = defineModel<string>()
...
model.value = 'hello world';
console.log(model.value); // I would expect that this would always print 'hello world' regardless of how it is connected to the parent component
If this behavior is not possible, then it would also be acceptable if the model was always updated in the next tick. At least that would make it consistent.
What is actually happening?
The component's behavior is different depending on if how it is connected in the parent.
If both the prop and update events are hooked up (manually or with v-model
), then the model does not update to the new value until after a tick has passed, and reading it immediately will result in the old value being read. This happens even if the onUpdate:modelValue
handler does not update the modelValue
.
If either or both the prop or event are not hooked up, then the model updates immediately to the new value within the same tick, and can be read right away.
System Info
System:
OS: Windows 11 10.0.26100
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 3.56 GB / 31.73 GB
Binaries:
Node: 22.16.0 - C:\Program Files\nodejs\node.EXE
npm: 11.4.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (130.0.2849.80)
Internet Explorer: 11.0.26100.1882
Any additional comments?
No response