Props keys always being set in 3.1.0-beta.1 results in a breaking change
Version
3.1.0-beta.1
Reproduction link
Steps to reproduce
- Open reproduction. The code is running 3.1.0-beta.7.
- Observe that there are two "test-cmp" components. The first one has its value set using the "value" prop. The second one has its value set using v-model.
- In the preview area, observe that the first component renders "undefined", and the second one renders "My Value with v-model".
- Change the reproduction to use Vue 3.0.11.
- Observe that this time the first component renders "My Value" instead of "undefined".
This seems to be related to https://github.com/vuejs/vue-next/commit/4fe4de0a49ffc2461b0394e74674af38ff5e2a20.
What is expected?
I would expect that the modelValue
key is not set unless actually using v-model.
What is actually happening?
The modelValue
key is set even in instances of my component that do not use v-model.
This impacts Ionic Vue applications. In Ionic Vue, we need to account for both value
and modelValue
so that we can set the correct component value on the underlying Web Component. Currently we use the following check:
const propsToAdd = {
'value': props.hasOwnProperty('modelValue') ? props.modelValue : props.value
}
With Vue 3.1.0 since the modelValue
key is always there, this condition is always true which breaks components that are using value
instead of v-model
. The workaround is pretty simple:
const propsToAdd = {
'value': props.hasOwnProperty('modelValue') && props.modelValue !== undefined ? props.modelValue : props.value
}
But at the same time this feels like a breaking change and should either be done in Vue 4.0 or noted in the changelog if breaking changes are allowed for minor releases.
This was intended. You have a workaround at https://github.com/vuejs/vue-next/issues/3288#issuecomment-835566953
Maybe this should be documented
I would consider a change in behavior to the public props API to be a breaking change in this case, so it would be helpful to have this documented.
Yes, this is an unfortunate case where the behavior inconsistency between Vue 2 and Vue 3 led to code that relies on the Vue 3 behavior. However it is still considered a fix since the behavior consistency has a higher priority.
I've updated pending 3.1 docs update to document this in https://github.com/vuejs/docs-next/pull/1078/commits/e41f44167f637bbff1f7c3ee041e8e7b37d56e22
Also added it to the release note draft.