Skip to content

Commit 5494731

Browse files
committed
fix(runtime-dom): prevent unnecessary updates in v-model checkbox when value is unchanged
1 parent 35785f3 commit 5494731

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/runtime-dom/src/directives/vModel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,26 @@ export const vModelCheckbox: ModelDirective<HTMLInputElement> = {
160160

161161
function setChecked(
162162
el: HTMLInputElement,
163-
{ value }: DirectiveBinding,
163+
{ value, oldValue }: DirectiveBinding,
164164
vnode: VNode,
165165
) {
166166
// store the v-model value on the element so it can be accessed by the
167167
// change listener.
168168
;(el as any)._modelValue = value
169169
let checked: boolean
170+
let isSimpleValue = false
170171

171172
if (isArray(value)) {
172173
checked = looseIndexOf(value, vnode.props!.value) > -1
173174
} else if (isSet(value)) {
174175
checked = value.has(vnode.props!.value)
175176
} else {
177+
isSimpleValue = true
176178
checked = looseEqual(value, getCheckboxValue(el, true))
177179
}
178180

179181
// Only update if the checked state has changed
180-
if (el.checked !== checked) {
182+
if (el.checked !== checked && (!isSimpleValue || value !== oldValue)) {
181183
el.checked = checked
182184
}
183185
}

0 commit comments

Comments
 (0)