-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Unexpected DOM Updates When Wrapping Checkbox in a Vue Component #11647
Comments
I found something weird with
beforeUpdate(el, { value, oldValue, modifiers: { lazy, trim, number } }, vnode) {
// ...
if (elValue === newValue) {
return
}
// ...
el.value = newValue
}, And here's beforeUpdate(el, binding, vnode) {
el[assignKey] = getModelAssigner(vnode)
setChecked(el, binding, vnode)
},
function setChecked(el, { value, oldValue }, vnode) {
el._modelValue = value
if (Array.isArray(value)) {
el.checked = value.indexOf(vnode.props.value) > -1
} else if (value instanceof Set) {
el.checked = value.has(vnode.props.value)
} else if (value !== oldValue) {
el.checked = value == getCheckboxValue(el, true)
}
} See how I think there are a few problems:
Maybe we could make What do you think? Should I try to make a fix for this? |
@Procrustes5 |
Upon further investigation, I discovered that this might be one of the causes of the update issue. In the core/packages/runtime-dom/src/modules/props.ts Lines 25 to 46 in c183405
I attempted to adjust the condition so that when const oldValue = tag === 'OPTION' ? el.getAttribute('value') || '' : el.value
const newValue = value == null
? el.type === 'checkbox'
? 'on'
: ''
: String(value) This adjustment appears to resolve the DOM update issue. May I open a PR with this approach? If there are any aspects I have overlooked, I would be very grateful for your feedback. |
Vue version
v3.4.38
Link to minimal reproduction
https://play.vuejs.org/#eNp9VE1v2zAM/SuCL3EBz8G6nbIkxVYE2IZlLbpiO8w7ODGTqZMlQR9phiD/vZQU2WoS5GBAIh+pR/KZu+yjlOXGQjbKxnqpqDREg7FyWnHaSqEM2REFK7InKyVaMkDooHPd/oXlv4XYHnzlMBpcRoQtBdeGLJ0Rmrdk4jLlq5ppuDpyXh85x8NABmngxUArWW0Ab4SMKZfWkM2bVjTAJlUW81cZMf8lRAvSQMtoUzPrbJY3sKIcGjQOQ6KO/kmu6wNoPEyezorMaGS9ouvySQuOLdu5PBglWkkZqDtpKFZVZSPiPc5XMyaev3qbURaKaPcvnbE/aaQ9wsO9Ag1qA1XW+Uyt1mCCe/bjO2zx3DmxBMsQfcH5AFow6zgG2CdsCtJOcJ7tFz9dytePerY1wHUsyhF1yL3HVxlO+fZC6T3dd+V7H1fxPXYxVcmx7gir+RoHYTBVqkHB58JyA80rJX5IEG4IFgHFiV4RFeUmlZAatRa0cO9u+e+Bn/5PJ5RBgSH+8KeTKLTUdCEzvLgQKxtUxSiJdAExhIllzQ6S9k+WPbDL25t+KWrqBQOMiFXkvovYvvwqNlRhfxQPJST5yM1NeK/0xPv5YD9zb+oyuEryM9QLEnABlSRDQn1SHF5Sov8LH7DTvsrx58f5txmDFriZ5gjr5pVjAZNpYBAixQJjODyTuTW1U83dwgtdpdAAFgxKJtb5oD1AB55j4EEwUylCbB7pBN5FTFIbo+gCG6qT38yFu+/Skmnoxh+6fYNFoizjM7gf+qVxOsh08YQGntlN4aFheOn1ptm/ACJ26e0=
Steps to reproduce
<input>
does not show any updates.<input>
flickers (updates).2024-08-19.12.28.35.mov
What is expected?
In this straightforward reproduction, the corresponding
<input>
DOM should not be updated when clicking on the Checkbox, as there are no updates besidesmodelValue
.What is actually happening?
The following code does not update the DOM, which is expected:
However, when this code is wrapped into a component, the DOM flickers (updates) every time the Checkbox is clicked.
Checkbox.vue
System Info
Any additional comments?
If the default value for
value
is changed to an empty string, this issue does not occur.Link to reproduction 2
The text was updated successfully, but these errors were encountered: